4

I created an WebApi in Asp.Net Core 1.1, which is hosted in Azure. Sending e-mails is a part of this Api. To do this, I used MailKit.SmtpClient with following code:

using (var client = new SmtpClient())
{
                client.LocalDomain = "smtp.office365.com";
                await client.ConnectAsync("smtp.office365.com", 587, SecureSocketOptions.StartTls).ConfigureAwait(false);
                client.AuthenticationMechanisms.Remove("XOAUTH2");
                client.Authenticate(Constants.AccountData.Login, Constants.AccountData.Password);
                await client.SendAsync(mimeMessage).ConfigureAwait(false);
                await client.DisconnectAsync(true).ConfigureAwait(false);
}

It works very well until last week. Since then, each time I make

client.Authenticate(Constants.AccountData.Login, Constants.AccountData.Password);

I become error 535 5.7.3 Authentication unsuccessful I checked the O365 Account and I could normally log in to O365 using Microsoft Login Page and the credentials we use in the App. To be sure, we have changed the password for this account, but this did not help.

I decided to migrate the App to .Net Core 2.0 and check with SmtpClient from .NET libraries. I published the migrated App to Azure and cofigured the SmtpClient as in this post -> https://blogs.msdn.microsoft.com/benjaminperkins/2017/01/11/sending-email-from-an-azure-web-app-using-an-o365-smtp-server/

Right now I become Timeout (The operation has timed out.).

When the property EnableSsl = false, then I become some other Error, that the connection is not secured.

I tried also set the property

client.TargetName = "STARTTLS/smtp.office365.com";

but it does not help.

Does anyone have an idea what can i do to make it work?

I have the feeling that the problem is somewhere else (maybe in o365), but i do not know where to look... Any suggestion will be very helpful.

MPILI
  • 51
  • 1
  • 5
  • I wouldnt expect the targetname to start with STARTTLS, but I would have expected you to need enablessl to true. – BugFinder Jan 12 '18 at 11:09
  • Hi. This try with STARTTLS was just some hint I saw in internet and want to try it. I am preety sure, that EnableSsl has to be true - MS Support Site recommends Port 587 and TLS (https://support.office.com/en-us/article/How-to-set-up-a-multifunction-device-or-application-to-send-email-using-Office-365-69f58e99-c550-4274-ad18-c805d654b4c4). – MPILI Jan 12 '18 at 12:13
  • I have answered [my solution here](https://stackoverflow.com/a/70231003/1462600) hope it will help you. – sohal07 Dec 05 '21 at 02:16

0 Answers0