須要用到:異步
1.System.Net.Mail;spa
2.QQ郵箱的POP3/SMTP服務碼.net
QQ郵箱的POP3/SMTP服務碼獲取方法:
orm
1.打開qq郵箱:blog
2.進入設置頁面--》帳戶:(往下翻)開啓服務POP3/SMTP服務,QQ郵箱會給一個POP3/SMTP服務碼保存下來ip
代碼:get
-
-
-
-
-
-
-
-
-
- public static bool SentMailHXD(string to, string body, string title, string whichEmail, string path, string Fname)
- {
- bool retrunBool = false;
- MailMessage mail = new MailMessage();
- SmtpClient smtp = new SmtpClient();
- string strFromEmail = "";
- string strEmailPassword = "";
- try
- {
- mail.From = new MailAddress("" + Fname + "<" + strFromEmail + ">");
- mail.To.Add(new MailAddress(to));
- mail.BodyEncoding = Encoding.UTF8;
- mail.IsBodyHtml = true;
- mail.SubjectEncoding = Encoding.UTF8;
- mail.Priority = MailPriority.Normal;
- mail.Body = body;
- mail.Subject = title;
- smtp.Host = "smtp.qq.com";
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.Credentials = new System.Net.NetworkCredential(strFromEmail, strEmailPassword);
-
- smtp.Send(mail);
- retrunBool = true;
- }
- catch (Exception ex)
- {
- retrunBool = false;
- }
-
- return retrunBool;
- }
調用方法便可:同步
- SentMailHXD("收件人", "內容, "標題", "抄送", "附件(附件方法我移除了)", "你的姓名");</span>