简体   繁体   English

如何使用域Windows身份验证从Office365帐户发送电子邮件

[英]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). (这要少得多)。

Settings for direct send 直接发送的设置

Enter the following settings on the device or in the application directly. 在设备上或在应用程序中直接输入以下设置。

  • Server/smart host. 服务器/智能主机。 Use your MX endpoint, for example, contoso-com.mail.protection.outlook.com 使用您的MX终结点,例如contoso-com.mail.protection.outlook.com
  • Port. 港口。 Use port 25 使用端口25
  • TLS/StartTLS. TLS / StartTLS。 Enable this. 启用它。
  • Email address. 电子邮件地址。 Use any email address for one of your Office 365 accepted domains. 使用任何电子邮件地址作为Office 365接受域之一。 This email address does not need to have a mailbox. 该电子邮件地址不需要邮箱。

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.

相关问题 如何使用Office365帐户从Azure网站发送带有附件的电子邮件 - How to send email with attachment from Azure Web Site using office365 account 如何在 asp.net C# 中使用启用双重身份验证的 office365 email 帐户发送 email? - How to send email using two factor authentication enabled office365 email account in asp.net C#? 使用office365发送电子邮件 - Send email using office365 使用设置为代表电子邮件帐户 B 发送的 Office365 电子邮件帐户 A 使用 SendGrid API 发送电子邮件 - Send email with SendGrid API using Office365 email account A which is set to send on behalf of an email account B 使用 Microsoft Graph 从 Office365 email 获取附件 - Get attachments from Office365 email using Microsoft Graph 使用MVVM的Office365 Windows应用程序 - Office365 Windows Application using MVVM 无需验证即可获取Office365电子邮件的日历 - Get calendars of office365 email without authentication 如何使用 VB.NET 或 C# 代码从启用了多因素身份验证的 Office 365 帐户发送电子邮件? - How to send emails by using VB.NET or C# code from an office 365 account that multi factor authentication enabled on it? C# 发送 email 与 office365 smtp - C# send email with office365 smtp 不允许在Office365上代表我的客户发送电子邮件 - Not allow to send email on behalf of my client on office365
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM