读书人

关于发邮件的有关问题多次尝试请大

发布时间: 2013-11-23 10:52:51 作者: rapoo

关于发邮件的问题,多次尝试,请大家帮帮忙。
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);
}
}
}


//调用

SendMail mail = new SendMail("xx@xx.com","pwd");


string[] addressee = { "xx@xx.com", "xx@xx.com" };
try { mail.SendE_Mail(addressee); Console.WriteLine("success"); }
catch (Exception ex) { Console.WriteLine(ex.Message); }
//输出success


邮件是发送成功了,但是看不到标头。标头具体是怎么添加的?
[解决办法]
你就设置了发件人,收件人和主题啊,这些都看不到?
[解决办法]

private void sendMail(string mailSubject, string mailBody, string attachement, string mailTo, string mailCc, string senderName, string displayName, string mailServer, string mailAccount, string password)
{

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);
}

try
{
sc.Send(mms);
}
catch (Exception ex)
{
throw ex;
}

}

[解决办法]
少年,你太水了吧
用哥的代码吧
[解决办法]
引用:
Quote: 引用:

少年,你太水了吧
用哥的代码吧

标头,大哥,怎么给邮件添加标头?


你说的标头不是邮件的标题?

mms.Subject = mailSubject;
[解决办法]
没设置过,邮件标头需要主动设置吗?
[解决办法]
SmtpClient _smtpClient = new SmtpClient();


_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
_smtpClient.Host = SMTP;//指定SMTP服务器
_smtpClient.Credentials = new System.Net.NetworkCredential(Mail, PWD);//用户名和密码

MailMessage _mailMessage = new MailMessage(new MailAddress(Mail, displayName), new MailAddress(to));
_mailMessage.Subject = subj;//主题
_mailMessage.Body = bodys;//内容
_mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
_mailMessage.IsBodyHtml = true;//设置为HTML格式
_mailMessage.Priority = MailPriority.High;//优先级
_smtpClient.Send(_mailMessage);

你是想指邮箱别名?
[解决办法]

引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

少年,你太水了吧
用哥的代码吧

标头,大哥,怎么给邮件添加标头?


你说的标头不是邮件的标题?

mms.Subject = mailSubject;

MailMessage message = new MailMessage("xx@163.com", Addressee[i], "Subject: Realizing Value from IT Investment", "");


有设置过,标头不是邮件的标题。


你是不是提示:在邮件标头中找到无效的字符

读书人网 >asp.net

热点推荐