关于发邮件的问题,多次尝试,请大家帮帮忙。The following email header is expected:Sender: web@reasonab
关于发邮件的问题,多次尝试,请大家帮帮忙。 The following email header is expected: Sender: <web@reasonables.com> Return-Path: <web@reasonables.com> Received: from iron2.hkstp.org [202.94.235.243] by MAIL.REASONABLES.COM with SMTP; Sun, 26 Aug 2012 04:16:05 -0400 Received: from smtp.hkstp.org ([192.168.106.16]) by iron2.hkstp.org with ESMTP/TLS/DHE-RSA-AES256-SHA; 26 Aug 2012 16:16:12 +0800 Received: from ri (mail01.edm.hkstp.org [202.94.235.148]) by smtp.hkstp.org (8.13.4/8.13.4) with ESMTP id n2M8FW4L031832 for <alan@reasonables.com>; Sun, 26 Aug 2012 16:16:12 +0800 Date: Sun, 26 Aug 2012 16:16:12 +0800 From: John Smith<johnsmith@reasonables.com> Reply-To:<web@reasonables.com> To: <hr@reasonables.com> Subject: Realizing Value from IT Investment
添加邮件标头,貌似我的代码无效。
代码如下:
public class SendMail { public SendMail() { } public string mail { get; set; } public string pwd { get; set; } public SendMail(string _mail,string _pwd) { this.mail = _mail; this.pwd = _pwd; }
public void SendE_Mail(string[] Addressee) { SmtpClient smtp = new SmtpClient("smtp.163.com", 25);//or localhost. Use local IIS SMPT as SMPT server.smtp. smtp.Credentials = new NetworkCredential(mail,pwd); for (int i = 0; i < Addressee.Length; i++) { MailMessage message = new MailMessage("xx@163.com", Addressee[i], "Subject: Realizing Value from IT Investment", ""); NameValueCollection c = new NameValueCollection(); c.Add("Sender", "<web@reasonables.com>"); c.Add("Return-Path", "<web@reasonables.com>"); c.Add("Received", "from iron2.hkstp.org [202.94.235.243] by MAIL.REASONABLES.COM with SMTP; /r/n/t Sun, 26 Aug 2012 04:16:05 -0400"); c.Add("Received", "from smtp.hkstp.org ([192.168.106.16]) /r/n/t by iron2.hkstp.org with ESMTP/TLS/DHE-RSA-AES256-SHA; 26 Aug 2012 16:16:12 +0800"); c.Add("Received", "from ri (mail01.edm.hkstp.org [202.94.235.148])/r/n/tby smtp.hkstp.org (8.13.4/8.13.4) with ESMTP id n2M8FW4L031832 /r/n/t for <alan@reasonables.com>; Sun, 26 Aug 2012 16:16:12 +0800"); c.Add("Date", "Sun, 26 Aug 2012 16:16:12 +0800"); c.Add("From", "John Smith<johnsmith@reasonables.com>"); c.Add("Reply-To", "<web@reasonables.com>"); c.Add("To", "<hr@reasonables.com>"); c.Add("Subject", "Realizing Value from IT Investment"); message.Headers.Add(c); smtp.Send(message); } } }
String[] toList = mailTo.Split(','); System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
sc.Host = mailServer; System.Net.Mail.MailMessage mms = new System.Net.Mail.MailMessage(); mms.Body = mailBody; mms.From = new System.Net.Mail.MailAddress(senderName, displayName); mms.Subject = mailSubject;
for (int i = 0; i <= toList.Length - 1; i++) { mms.To.Add(toList[i]); }
if (mailCc != null) { String[] ccList = mailCc.Split(','); for (int i = 0; i <= ccList.Length - 1; i++) { mms.CC.Add(ccList[i]); } }
if (File.Exists(attachement)) { System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(attachement, System.Net.Mime.MediaTypeNames.Application.Octet); mms.Attachments.Add(data); sc.Credentials = new NetworkCredential(mailAccount, password); }