[英]How to send an email from office365 account using domain windows authentication
I'm developing a console app which will be executed from a windows service that needs to send emails using the domain account associated to the domain account running the windows service. 我正在开发一个控制台应用程序,它将从Windows服务执行,该服务需要使用与运行Windows服务的域帐户相关联的域帐户发送电子邮件。
In my development machine I'm logged with a domain account that belongs to the same domain that will run the windows service but I'm not able to get it working properly. 在我的开发机中,我登录了一个域帐户,该域帐户将与运行Windows服务的域相同,但无法使其正常运行。
For this development I'm using .NET 4.6.1 and the nuget package FluentEmail.Smtp 对于此开发,我使用.NET 4.6.1和nuget包FluentEmail.Smtp
My code looks like this: 我的代码如下所示:
Email.DefaultSender = new SmtpSender(new SmtpClient
{
UseDefaultCredentials = true,
EnableSsl = true,
Host = "smtp.office365.com",
TargetName = "STARTTLS/smtp.office365.com",
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network
});
await Email.From("myname@mycompanydomain.com", "Some tittle")
.To(emailListObject)
.Subject("Some subject")
.Body("Some body", true)
.SendAsync();
With this code I'm getting the following exception: 有了这段代码,我得到了以下异常:
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 52.96.9.178:587
at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
Note: From my machine I'm able to ping the IP mentioned in the exception 注意:从我的机器上,我可以ping异常中提到的IP
I'll appreciate your assistance 多谢您的协助
For starters you might want to take a look at the official document - direct send . 对于初学者,您可能需要查看官方文档-直接发送 。 You will note that there are quite a few issues (such as TLS security) alongside proper configuration of your Exchange server.
您会注意到,在正确配置Exchange服务器的同时,还有很多问题(例如TLS安全性)。
Without more information in your question it is rather limited as to what can be answered, however as an alternate solution, maybe take a look at direct send. 如果您的问题中没有更多信息,那么可以回答的内容非常有限,但是作为替代解决方案,您可以看看直接发送。 (which is much less effort).
(这要少得多)。
Enter the following settings on the device or in the application directly. 在设备上或在应用程序中直接输入以下设置。
contoso-com.mail.protection.outlook.com
contoso-com.mail.protection.outlook.com
Microsoft recommends adding an SPF record to avoid having messages flagged as spam. Microsoft建议添加SPF记录,以避免将邮件标记为垃圾邮件。 If you are sending from a static IP address, add it to your SPF record in your domain registrar's DNS settings as follows:
如果您是从静态IP地址发送的,则将其添加到域注册商的DNS设置中的SPF记录中,如下所示:
DNS entry Value
SPF v=spf1 ip4:<Static IP Address> include:spf.protection.outlook.com ~all
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.