【发布时间】:2020-02-11 16:30:47
【问题描述】:
我有一个简单的 C# 应用程序,它从“noreply@domain.com”发送带有附件的电子邮件。如果我使用自己的电子邮件地址,那么效果很好。任何其他电子邮件,结果错误。消息服务器团队无法解决,因为他们在配置中的服务器设置中没有发现任何问题。我的应用程序非常简单但无法正常工作。这是代码。
ReportDocument cryRpt = new ReportDocument();
AutoTCs AutoTC = new AutoTCs();
AutoTC.DataSourceConnections[0].SetConnection(ConfigurationSettings.AppSettings["DBServer"], ConfigurationSettings.AppSettings["DBName"], ConfigurationSettings.AppSettings["DBUserId"], ConfigurationSettings.AppSettings["DBPwd"]);
//CredentialCache myCache = new CredentialCache();
Stream ms;
ms = (Stream)AutoTC.ExportToStream(ExportFormatType.PortableDocFormat);
Attachment attch = new Attachment(ms, "AutoTC_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_AM.pdf");
MailMessage emsg = new MailMessage(System.Configuration.ConfigurationSettings.AppSettings["FromAddress"], ConfigurationSettings.AppSettings["ToAddress"], "Auto TC Report " + DateTime.Now.Month + "/" + DateTime.Now.Day + " AM", "Please find the Auto TC report ");
string[] arInfo = new string[4];
// define which character is seperating fields
char[] splitter = { ';' };
arInfo = ConfigurationSettings.AppSettings["CCAddress"].ToString().Split(splitter);
for (int x = 0; x < arInfo.Length; x++)
{
emsg.CC.Add(arInfo[x]);
}
emsg.Attachments.Add(attch);
SmtpClient smtp = new SmtpClient(ConfigurationSettings.AppSettings["SMTP"]);
smtp.Port = 587;
smtp.UseDefaultCredentials = true;
//smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
//smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Send(emsg);
在地址中,我只是输入“noreply@noreply.domain.com”
给出此错误“邮箱不可用。服务器响应为 5.7.1 客户端无权作为此发件人发送"
我检查了其他端口号 25,但随后出现“通道未打开”类型的错误消息。
【问题讨论】:
-
听起来您无权从除您自己的电子邮件地址之外的任何其他电子邮件地址发送电子邮件。错误消息似乎很清楚。我非常怀疑这是你的代码的错。我猜可能服务器团队不认为这是一个问题,因为这就是他们期望他们的安全工作的方式?我不知道它是哪种邮件服务器,但大概你需要一些额外的权利或特权才能被允许代表其他人发送邮件。
-
电子邮件中的发件人地址必须与电子邮件服务器帐户的电子邮件地址相同。
-
发件人地址来源于默认凭据,您必须使用默认凭据通过网络获取密码。
-
我已经尝试了所有我知道的东西。使用了不同的凭据,没有任何效果。
标签: c# smtp credentials smtpclient