我使用以下代码发送电子邮件。电子邮件已成功接收到工作中的收件人,但不会在外面收到。我试图发送电子邮件到我的Gmail帐户和同样的问题,我无法收到它。 在工作中,我们正在使用Exchange 2010.我在gmail中检查了垃圾邮件,但未找到任何电子邮件。
我的代码:
public bool SendEmail()
{
try
{
var mailMessage = CreateMailMessage();
var client = new SmtpClient()
{
Credentials = new NetworkCredential(Resources.Username, Resources.Password, Resources.Domain),
Port = 25,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = ConfigurationProperties.ExchangeIPAddress
};
client.Send(mailMessage);
}
catch (Exception ex)
{
LogFile.Write(string.Format("EmailManager::SendEmail failed at {0}", DateTime.Now.ToLongTimeString()));
LogFile.Write(string.Format("Error: {0}", ex.Message));
return false;
}
return true;
}
private MailMessage CreateMailMessage()
{
var mailMessage = new MailMessage();
mailMessage.Subject = ConfigurationProperties.EmailSubject;
mailMessage.Body = ConfigurationProperties.EmailBody;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
LogFile.Write(string.Format("Subject= {0}", mailMessage.Subject));
LogFile.Write(string.Format("Body= {0}", mailMessage.Body));
AddRecipients(mailMessage);
return mailMessage;
}
为了让外部电子邮件收件人接收电子邮件,我是否缺少任何财产?
答案 0 :(得分:1)
您无法设置允许邮件通过网络的属性。这听起来像是Exchange服务器上的配置,与System.Net.Mail没有任何关系。
您需要与系统管理员联系。