111,126
社区成员
发帖
与我相关
我的任务
分享
MailMessage testMail = new MailMessage();
testMail.From = new MailAddress(txtBoxFrom.Text);
testMail.To.Add(new MailAddress(txtBoxTo.Text));
testMail.Subject = txtBoxSubject.Text;
testMail.BodyEncoding = System.Text.Encoding.UTF8;
testMail.IsBodyHtml = true;
testMail.Body = richTxtBoxContent.Text;
testMail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient(txtBoxSmtpSever.Text,587);//或者是587、465
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("****@gmail.com", "****");
client.EnableSsl = true;
try
{
this.Cursor = Cursors.WaitCursor;
client.Send(testMail);
this.Cursor = Cursors.Default;
MessageBox.Show("发送成功");
}
catch (Exception ee)
{
this.Cursor = Cursors.Default;
richTxtBoxContent.Text = ee.Message;
}
Dim message As New System.Net.Mail.MailMessage
message.From = New MailAddress("xxx@gmail.com") '"Your DisplayName"
message.To.Add(New MailAddress("xxx@hotmail.com")) ' the email you want to send email to
Message.Subject = "A test email"
message.IsBodyHtml = True
message.BodyEncoding = System.Text.Encoding.UTF8
Message.Body = "this is just a simple test!<br> Jack"
message.Priority = MailPriority.High
Dim client As New SmtpClient("smtp.gmail.com", 587) ' // 587;//Gmail使用的端口
client.Credentials = New System.Net.NetworkCredential("xxx@gmail.com", "xxx") ' // Your user name & password
client.EnableSsl = True ' //经过ssl加密
Try
client.Send(message)
Debug.Print("邮件发送到" + message.To.ToString() + "<br>")
Catch ex As Exception
Debug.Print(ex.Message + "<br>" + ex.InnerException.Message)
End Try