我正在尝试从我的C#Windows应用程序Localhost发送邮件。在发送邮件时,它会收到异常消息"发送邮件失败"。
在smtpClient.Send(message);
行。有什么问题?
SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
StringBuilder bodyMessage = new StringBuilder();
bodyMessage.Append("Error Importing the Asset XML File.");
try
{
MailAddress to = new MailAddress("iramasani@gmail.com");
MailAddress from = new MailAddress(smtpSection.From);
MailMessage message = new MailMessage(from, to);
message.Subject = "Error importing the Asset XML File.";
message.Body = bodyMessage.ToString();
SmtpClient smtpClient = new SmtpClient(smtpSection.Network.Host, smtpSection.Network.Port);
smtpClient.UseDefaultCredentials = true;
smtpClient.Send(message);
}
catch (Exception ex)
{
LogError("Error Sending mail "+ ex.Message);
}
}
在app.config
:
<configuration>
<system.net>
<mailSettings>
<smtp from="admin@alticore.com">
<network host="localhost" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>