傳送Email
//Send Email
private void emailSend(string code)
{
//驗證發生的郵件地址不能為空;
if (String.IsNullOrWhiteSpace(this.txtUserMail.Text))
{
showErr("郵件地址");
return;
}
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(this.txtUserMail.Text);//收件人郵箱
mailMessage.From = new MailAddress("[email protected]
mailMessage.Subject = "this is a Test.";
mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
mailMessage.Body = "你申請的驗證碼是:" + code ;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
mailMessage.IsBodyHtml = false;
mailMessage.Priority = MailPriority.High;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "ergerg");
smtpClient.Host = "smtp.exmail.qq.com";
object userState = mailMessage;
try
{
smtpClient.SendAsync(mailMessage, userState);
showErr("驗證碼已經發送到你的郵箱中,", "請注意查收!");
}
catch (SmtpException ex)
{
showErr("發生失敗!原因:", ex.ToString());
}
}