Forum Discussion

jemes715's avatar
jemes715
Copper Contributor
Jul 14, 2022

mail send using smtp.office365.com failed

Hi I'm used to send mail from asp.net mvc,C# code but the problem is its not work from site which start with HTTP, not any problem for send mail from site start with HTTPS. I didn't get what's the problem for this issue. I'm used below code for send mails

var hostEmail = ConfigurationExtensions.GetAppConfigValue("SMTPUserName").ToString();
var hostPassword = ConfigurationExtensions.GetAppConfigValue("SMTPPassword").ToString();
var fromEmail = ConfigurationExtensions.GetAppConfigValue("EmailFrom").ToString();

SmtpClient ss = new SmtpClient
{
    Host = ConfigurationExtensions.GetAppConfigValue("EmailHost").ToString(),
    Port = ConfigurationExtensions.GetAppConfigValue<int>("smtpPort"),
    Timeout = 20000,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = true,
    EnableSsl = true,
    Credentials = new NetworkCredential(hostEmail, hostPassword)
};

MailMessage mailMsg = new MailMessage(hostEmail, email, subject, msg)
{
    From = new MailAddress(fromEmail, mailname),
    IsBodyHtml = true,
    DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
};
ss.Send(mailMsg);

My config code send below

<add key="EmailHost" value="smtp.office365.com" />
<add key="EnableSsl" value="true" />
<add key="smtpPort" value="587" />
<add key="SMTPUserName" value="email address removed for privacy reasons" />
<add key="SMTPPassword" value="password" />
<add key="EmailFrom" value="email address removed for privacy reasons" />
<add key="EmailUser" value="Test User" />
<add key="EmailID" value="email address removed for privacy reasons" />

Error screenshots attached below https://i.stack.imgur.com/L3j43.png https://i.stack.imgur.com/4hTU1.pnghttps://www.globalfintechleaders.com/

Also checked this issue in different sites but not get the solution. Problem only exist while sites start in http:, not any issues in https:
Anybody know the solution ? please help me to solve this issue.

Thanks in advance

1 Reply

  • Markus Meyer's avatar
    Markus Meyer
    Copper Contributor

    jemes715 

    Exactly the same happened to me.
    I had the following exception:

     

    Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant.
    Visit https://aka.ms/smtp_auth_disabled for more information.

     

     

    You have to allow SMTP for the account (again).

    https://docs.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission#use-exchange-online-powershell-to-enable-or-disable-smtp-auth-on-specific-mailboxes :
    This example enables SMTP AUTH for mailbox mailto:email address removed for privacy reasons.

     

    Set-CASMailbox -Identity email address removed for privacy reasons -SmtpClientAuthenticationDisabled $false

     

     

    https://borncity.com/win/2022/07/13/outlook-streikt-beim-mail-versand-microsoft-hat-smtp-deaktiviert-juli-2022/