使用电子邮件发送Smtp.mail.microsoftonline.com [英] Sending email using Smtp.mail.microsoftonline.com

查看:236
本文介绍了使用电子邮件发送Smtp.mail.microsoftonline.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的上下文:

我们是一家小公司,没有一个Exchange服务器(或任何人专门给它)但我们仍然需要有/发送电子邮件。

We’re a small company that does not have an Exchange Server (or anyone dedicated to it) yet we still need to have/send emails.

我们已经决定使用微软在线服务(MOS)

的目标:

我们有一个web服务器(Windows Server 2003 R2中使用IIS 6.0),并部署了C#ASP.Net应用MCV

We have a web server (Windows Server 2003 R2 with IIS 6.0) and have deployed a C# ASP.Net MCV application.

Web应用程序需要每个用户创建一个帐户时发送电子邮件。

The web application needs to send emails each time a user creates an account.

根据我们需要使用的端口(587),并确保传输层安全(TLS)使-exchange-online.aspx>文档。此外,被使用的类型必须是权威,这是我的两倍通过的 Microsoft联机管理中心

中的代码:

C#代码我应该是微不足道的,是以下内容:

The C# code I have should be trivial and is the following:

SmtpClient server = new SmtpClient("Smtp.mail.microsoftonline.com");
server.Port = 587;
server.EnableSsl = true;
server.Credentials = new System.Net.NetworkCredential("xxx@domain.com", "123abc");
server.UseDefaultCredentials = false;

MailMessage mail = new MailMessage();
mail.From = new MailAddress("xxx@domain.com");
mail.To.Add("johndoe@domain.com");
mail.Subject = "test subject";
mail.Body = "this is my message body";
mail.IsBodyHtml = true;

try
{
    server.Send(mail);
}
catch (Exception ex)
{
    throw ex;
}






错误

我已经创建与上面的代码一个简单的WinForm的应用程序来测试发送电子邮件,...
我测试过的WinForm应用程序。本地我的计算机(Windows XP)上,并在服务器上

I’ve created a simple winform application with the above code to test the sending of emails… I’ve tested the winform application locally on my computer (Windows XP) and on the Server.

在这两个尝试,我不断收到以下错误信息:

In both attempt, I keep receiving the following error message:

SMTP服务器要求安全连接或客户端未通过身份验证。服务器响应为:5.7.1客户端未通过身份验证

谷歌搜索过了一会儿,我还没有发现的原因。另外,大多数我发现正在为在 Exchange管理控制台这似乎不有(或安装),因此为什么我们使用微软在线服务...

After Googling for a while I still haven’t found the reason why…In addition, most of the answers I’ve found are making a reference to the Exchange Management Console which we don’t seem to have (or installed) hence why we are using Microsoft Online Services…

问题:

1)作为支付MOS的客户,我最初的理解是,我不应该安装(或有),我们的服务器上的Exchange管理控制台......其实,这应该是为了实现我的任务完全不相干的。

1) As a paying customer of MOS, my initial understanding is that I shouldn’t have to install (or have) an Exchange Management Console on our server…in fact, this should be completely irrelevant in order to achieve my task.

2)我也试着使我们的IIS 6.0里面,但无济于事...

2) I’ve also tried enabling TLS inside our IIS 6.0 but to no avail…

TLS 3)我们在这里救命稻草抓是因为我们似乎做什么样子的东西惊人的小事......

3) We are grasping at straws here because what we seem to do looks like something amazingly trivial…

4)我们应该干脆放弃使用MOS的SMTP服务器的想法,并用另一个呢?比如Gmail的?如果是这样......那么为什么还要支付月租费MOS?

4) Should we simply abandon the idea of using MOS’s SMTP server and use another one? Such as Gmail’s ? If so…then why bother paying a monthly fee for MOS?

如果任何人有任何帮助/建议,可以帮助我摆脱这方面的一些光,那将是巨大的!

If any one has any help/advice that can help me shed some light on this, that would be great!

真诚
文斯

哇...我相信我们已经找到了元凶

WOW…I believe we’ve found the culprit!!!

通过注释这行代码

//server.UseDefaultCredentials = false;



一切都开始工作了!

Everything started to work!

我现在中号能够发送内部和我们的外域...

I’m now able to send emails inside and outside our domain…

令我百思不解的电子邮件的最多的是,根据该文件,这个默认值 UseDefaultCredentials 属性设置为

What puzzles me the most is that, according to the documentation, the default value of this UseDefaultCredentials property is set to false

所以...当我手动将其设置为这是行不通的,但是当我评论线(也设置其为false,因为它的默认值),它的作品!

So…when I manually set it to false it doesn’t work but when I comment the line (which also set’s it to false because of its default value) it works!

如果这是一个已知的问题,或者如果任何人有一个答案,我很好奇,想知道!

If this is a known issue or if anyone has an answer for that, I’d be curious to know!

真诚
谢谢

推荐答案

看在UseDefaultCredentials财产反射,你可以看到,它也改变了trasnport.Credentials值,所以当你叫这个属性用假值,它改变了运输凭证为null。
的问题是,你之前设置在线路的凭据后调用此属性,
是无效的凭据。

looking in Reflector on UseDefaultCredentials property, you can see that it also changes the trasnport.Credentials value, so when you called this property with a false value, it changed the transport credentials to null. the problem is that you called this property after setting the credentials in the line before that, it nullified the credentials.

这样的底线,你不应该设置凭据,并调用这个属性afterwise。

so bottom line, you shouldn't set the credentials and call this property afterwise.

这篇关于使用电子邮件发送Smtp.mail.microsoftonline.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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