通过Exchange Online的(365处)发送使用System.Net.Mail SMTP电子邮件 [英] Send SMTP email using System.Net.Mail via Exchange Online (Office 365)

查看:8473
本文介绍了通过Exchange Online的(365处)发送使用System.Net.Mail SMTP电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在测试新的Office 365测试版,我对Exchange Online服务邮件帐户。现在,我尝试连接一个LOB应用程序,可以从我的测试帐户发送SMTP电子邮件。



不过交易所365平台需要在端口587 TLS加密,并有 System.Net.Mail 的'功能'是不允许隐式SSL加密。



有没有人设法让C#通过这个平台发送邮件?



我有以下的基本代码,应。发送邮件 - 任何意见,将不胜感激。

  SmtpClient服务器=新SmtpClient(ServerAddress); 
server.Port = 587;
server.EnableSsl = TRUE;
server.Credentials =新System.Net.NetworkCredential(username@mydomain.com,密码);
server.Timeout = 5000;
server.UseDefaultCredentials = FALSE;

邮件MAILMESSAGE新= MAILMESSAGE();
mail.From =新的MailAddress(recipent @ anyaddress);
mail.To.Add(username@mydomain.com);
mail.Subject =测试出消息发送;
mail.Body =这是我的邮件正文;
mail.IsBodyHtml = TRUE;

server.Send(邮件);


解决方案

固定在上面的工作代码的几个错别字:

 味精MAILMESSAGE新= MAILMESSAGE(); 
msg.To.Add(新MailAddress(someone@somedomain.com,某人));
msg.From =新的MailAddress(you@yourdomain.com,你);
msg.Subject =这是一个测试邮件;
msg.Body =这是使用Exchange Online的测试消息;
msg.IsBodyHtml = TRUE;

SmtpClient客户端=新SmtpClient();
client.UseDefaultCredentials = FALSE;
client.Credentials =新System.Net.NetworkCredential(用户名,密码);
client.Port = 587; //您可以使用端口25,如果587被封锁(我的是!)
client.Host =smtp.office365.com;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = TRUE;

{
client.Send(MSG);
lblText.Text =消息发送成功与
}
赶上(异常前)
{
lblText.Text = ex.ToString();
}



我在使用上面的代码两个Web应用程序,并没有任何麻烦都做工精细


We are testing the new Office 365 beta, and i have a mail account on the Exchange Online service. Now I'm trying to connect a LOB application that can send smtp emails from my test account.

However the Exchange 365 platform requires TLS encryption on port 587, and there is a 'feature' of System.Net.Mail that does not permit Implicit SSL encryption.

Has anyone managed to get C# sending mails via this platform?

I have the following basic code that should send the mail - any advice would be appreciated.

SmtpClient server = new SmtpClient("ServerAddress");
server.Port = 587;
server.EnableSsl = true;
server.Credentials = new System.Net.NetworkCredential("username@mydomain.com", "password");
server.Timeout = 5000;
server.UseDefaultCredentials = false;

MailMessage mail = new MailMessage();
mail.From = new MailAddress("recipent@anyaddress");
mail.To.Add("username@mydomain.com");
mail.Subject = "test out message sending";
mail.Body = "this is my message body";
mail.IsBodyHtml = true;

server.Send(mail);

解决方案

Fixed a few typos in the working code above:

    MailMessage msg = new MailMessage();
    msg.To.Add(new MailAddress("someone@somedomain.com", "SomeOne"));
    msg.From = new MailAddress("you@yourdomain.com", "You");
    msg.Subject = "This is a Test Mail";
    msg.Body = "This is a test message using Exchange OnLine";
    msg.IsBodyHtml = true;

    SmtpClient client = new SmtpClient();
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("your user name", "your password");
    client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
    client.Host = "smtp.office365.com";
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = true;
    try
    {
        client.Send(msg);
        lblText.Text = "Message Sent Succesfully";
    }
    catch (Exception ex)
    {
        lblText.Text = ex.ToString();
    }

I have two web applications using the above code and both work fine without any trouble.

这篇关于通过Exchange Online的(365处)发送使用System.Net.Mail SMTP电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆