+1 vote

Hi,
I try to follew these guidence to send emails , later on we need also POP and IMAP :
https://www.limilabs.com/blog/oauth2-office365-exchange-imap-pop3-smtp

But when I've got my Token im still not be able to send any mail. It allready stops when trying to connect. All setting are the same as given in the guidelines.

lcConnectHost = "smtp.office365.com";
lnPort = 587;
client.ConnectSSL(lcConnectHost, lnPort);

gives:
“Authenticate as SSL/TLS client failed.
You might be connecting to non SSL/TLS port -or- using incorrect SSL/TLS version.
Consider using TLS 1.2: client.SSLConfiguration.EnabledSslProtocols = SslProtocols.Tls12;
Please examine the inner exception for details.”

When trying the ‘old’ way

client.Connect(lcConnectHost , lnPort);
client.StartTLS();
client.UseBestLogin(lcUser , lcPassw );

it fails with:
“Unrecognized authentication type [AM0PR10CA0060.EURPRD10.PROD.OUTLOOK.COM]”

Do you have any idea how to solve connecting and let us send emails?

Thanks in advance

by (2.0k points)

1 Answer

0 votes
 
Best answer

I don't think smtp.office365.com exists.

Use outlook.office365.com instead:

using (Smtp client = new Smtp())
{
    client.Connect("outlook.office365.com");
    client.StartTLS();

    //...

    client.Close();
}

Here you can find a full example:

https://www.limilabs.com/blog/oauth2-office365-exchange-imap-pop3-smtp

by (272k points)
edited by
Thanks,
 i tried many options, but none works... it could be that ExchangeOnline/Office 365 is not configured as need but to me it all looks simular to the instructions given ..


hereby a part of my source:
string lcConnectHost = "outlook.office365.com";
Int32 lnPort = 587;

Console.WriteLine(">> OPTION 1 -------------------------------------------------" );
client.Connect(lcConnectHost , lnPort);
client.StartTLS();
client.UseBestLogin( lcUser , lcPassw );


Console.WriteLine(">> OPTION 3 -------------------------------------------------");
client.Connect(lcConnectHost);
client.StartTLS();
client.LoginOAUTH2(user, accessToken);


Console.WriteLine(">> OPTION 4 -------------------------------------------------");
client.Connect(lcConnectHost);
client.StartTLS();
client.UseBestLogin(lcUser, lcPassw);


with this response:

>> OPTION 1 -------------------------------------------------
Authentication unsuccessful [AM0PR10CA0013.EURPRD10.PROD.OUTLOOK.COM]

>> OPTION 3 -------------------------------------------------
Authentication unsuccessful [AM4PR0902CA0007.eurprd09.prod.outlook.com]

>> OPTION 4 -------------------------------------------------
Authentication unsuccessful [AM0PR01CA0076.eurprd01.prod.exchangelabs.com]
I think you should ask your server administrator at least for your server address. Check if IMAP is turned on for this account.

When using UseBestLogin make sure Basic authentication is turned on (https://www.limilabs.com/blog/helpful-pop3-and-imap-exchange-2019-links).

For OAuth2 make sure scopes and permissions are correct.

You can examine these samples:

https://www.limilabs.com/blog/oauth2-office365-exchange-imap-pop3-smtp

https://www.limilabs.com/blog/oauth2-password-grant-office365-exchange-imap-pop3-smtp
...