【问题标题】:Sending mail in asp.net using Exchange Server(smtp-outlook.office365.com)使用 Exchange Server(smtp-outlook.office365.com) 在 asp.net 中发送邮件
【发布时间】:2016-01-18 22:11:30
【问题描述】:

我们正在使用 asp.net 中的邮件系统,我们的客户端使用 Microsoft Exchange 服务器 Outlook.office365。我们遇到了这个异常。

“System.Net.Mail.SmtpException:操作超时”错误。请帮助我们。

btn_click(){
try{SmtpClient smtp = new SmtpClient("smtp.outlook.office365.com");                             
                smtp.Host = "outlook.office365.com";
                smtp.Port = System.Convert.ToInt32("443");            
                System.Net.NetworkCredential cred = new System.Net.NetworkCredential("userid", "mypwd");
                smtp.Credentials = cred;            
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.EnableSsl = true;
                smtp.TargetName = "STARTTLS/outlook.office365.com";
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("frommailid", "username");
                msg.To.Add(new MailAddress("xxx@xxx.com"));            
                msg.Subject = "Test";
                msg.Body = "Test mail ";
                smtp.Timeout = 60000;
                smtp.Send(msg);
}catch(exception ex)
{
throw ex;
}
}

【问题讨论】:

  • 请分享您的代码以便我们调查问题?
  • 请检查上面的代码..
  • 尝试使用端口 587 而不是 443,如果可行,请更新我们
  • 如果它不起作用,请使用 {smtp.office365.com} 而不是 {smtp.outlook.office365.com}
  • “smtp.office365.com”不工作--超时错误

标签: asp.net email outlook exchange-server office365


【解决方案1】:

请参考以下代码 sn-p 并尝试一下。它对我有用。

记住:发件人字段应与用作 SMTP 用户的电子邮件 ID 相同。所以在这个例子中,xxx@blabla.onmicrosoft.com 应该是 From email id。

MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress(ToField.Text));
mail.From = new MailAddress(FromField.Text); //From field should be same email id which is used as a SMTP user.
mail.Subject = "Email Subject";
mail.Body = "Message Body";

SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("xxx@blabla.onmicrosoft.com", "Password");
client.Port = 587;//You can use Port 25 if 587 is blocked
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.TargetName = "STARTTLS/smtp.office365.com";

try {
    client.Send(mail);
} 
catch (Exception ex) {
    ResponseLabel.Text = "Error:" + ex.Message;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    相关资源
    最近更新 更多