Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

O365 Exchange Configuration (Works in Console) #2948


User avatar
0
justinp created

Hello,

I am trying to configure my SMTP settings in the application to send using our support@company.com mailbox. I tried using putting my O365 settings into the host configuration, but get the following error in the audit logs when I try to send a test email:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

I decided to build a small console app using the MailKit NuGet package to prove that the settings worked, and it does work fine. Here are the settings I'm putting in: Default from (sender) email address: support@company.com Default from (sender) display name: Company Support SMTP host: smtp.office365.com SMTP port: 587 Use SSL: false Use default credentials: false Domain name: company.com Username: myemail@company.com Password: password

The code to send the email is the following:

var message = new MimeMessage();
            message.From.Add(new MailboxAddress("Company Support", "[email protected]"));
            message.To.Add(new MailboxAddress("Me", "[email protected]"));
            message.Subject = "Hello World - A mail from ASPNET Core";
            message.Body = new TextPart("plain")
            {
                Text = "Hello World - A mail from ASPNET Core"
            };

            using (var client = new SmtpClient())
            {
                try
                {
                    client.Connect("smtp.office365.com", 587, false);
                    // Note: since we don't have an OAuth2 token, disable 	
                    // client.AuthenticationMechanisms.Remove("XOAUTH2");
                    // Note: the XOAUTH2 authentication mechanism.     
                    client.Authenticate("[email protected]", "password");
                    client.Send(message);
                    client.Disconnect(true);
                  }

This sends a test email just fine.

Does anyone have their application sending email through their O365 Exchange? Is there a way to get this working in ABP? Do I need to overwrite the current ABP mail implementation?


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you try same test with this class <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Net/Mail/Smtp/SmtpEmailSender.cs">https://github.com/aspnetboilerplate/as ... lSender.cs</a> ? You can copy this class to your console app and just rename it.

    Thanks.

  • User Avatar
    0
    Red created

    Office 356 smtp setting require the StartTLS secure socket option which is not implemented in aspnetboilerplate (there is only the enableSSL true and false options).

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @Red,

    If that is the case, then a custom implementation can be used instead of default email sender because email sending code is very simple.

  • User Avatar
    0
    mightyit created

    @justinp Clear the domain name field