需要用到:
1.System.Net.Mail;
2.QQ邮箱的POP3/SMTP服务码
QQ邮箱的POP3/SMTP服务码获取方法:
1.打开qq邮箱:
2.进入设置页面--》账户:(往下翻)开启服务POP3/SMTP服务,QQ邮箱会给一个POP3/SMTP服务码保存下来
代码:
-
-
-
-
-
-
-
-
-
- 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>
|
请发表评论