我通过System.web.mail发送邮件,我的代码如下 -
public static void SendEmail(string to, string from, string subject, string body, string SmtpServer, int SmtpPort, string SmtpUser,
string SmtpPassword, bool ssl)
{
try
{
MailMessage myMail = new MailMessage();
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", SmtpServer);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", SmtpPort);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//Use 0 for anonymous
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", SmtpUser);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", SmtpPassword);
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", ssl);
myMail.From = from;
myMail.To = to;
myMail.Subject = subject;
myMail.Body = body;
// System.Web.Mail.SmtpMail.SmtpServer = SmtpServer + ':' + SmtpPort;
System.Web.Mail.SmtpMail.Send(myMail);
}
catch (Exception ex)
{
throw;
}
}
此代码正在正确发送邮件,但当收件人收到电子邮件时,来自电子邮件的地址显示为网络凭据的用户名,而不是我传递的来自电子邮件地址。任何人都可以向我建议可能的解决方案吗?