• GoDaddy Community
  • VPS & Dedicated Servers
  • VPS & Dedicated Servers

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    Go to solution
    PatriceP
    Novice

    Email configuration for Azure hosted web site

    Hello,

     

    I am hosting a .NET core 2.0 web site on Microsoft Azure and the web applications sends emails. I was able to configure the application to send emails via GMAIL, but now, I just purchased a hosted web mail solution (Email Essentials plan) with you guys. The questions are:

    • What is the name of the SMTP relay server?
    • What is the port number?
    • Should I use a SSL connection ?
    • I used the email address that is defined in my plan along with its password to provide the credentials. Is it correct?

    This is my appsettings.json configuration for that piece of logic:

    "Smtp": {
            "From": "administrator@mydomain.com",
            "Port": "25",
            "SmtpServer": "relay-hosting.secureserver.net",
            "SslEnabled": "false",
            "UserName": "administrator@mydomain.com"
    }

    The password is stored in Azure Vault. I am using MimeKit API to send the email.

     

    On localhost, the code throws an exception when it executes this line:

    client.Connect("relay-hosting.secureserver.net", 25, false);

    and the exception is : System.Net.Internals.SocketExceptionFactory.ExtendedSocketException

     

    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 xx.xxx.xxx.xxx:25 where xx.xxx.xxx.xxx is a IP address that resolves to a "secureserver.net" server

     

    Any help would be appreciated.

     

    Thanks,

    2 REPLIES
    PatriceP
    Novice
    Solution

    Re: Email configuration for Azure hosted web site

    I  found the answers I was looking for...

     

    First, the SMTP information:

    • Server name: smtp.office365.com
    • Port: 587
    • Encryption method: STARTTLS

    This information, along with POP and IMAP settings, is available in Office 365. Connect to your account in Office 365 and click on the Cog (Settings) icon. Type: "POP and IMAP". 

     

    Then, the appsettings.json config looks like this:

    "Smtp": {
         "From": "administrator@mydomain.com",
         "Port": "587",
         "SmtpServer": "smtp.office365.com",
         "SslEnabled": "false",
         "UserName": "administrator@mydomain.com"
    }

     

    and the code that sends the email was modified to use the proper encryption:

    using (var client = new SmtpClient())
    {
         client.Connect("administrator@mydomain.com",

                                 587,

                                 MailKit.Security.SecureSocketOptions.StartTls);

         client.Authenticate(_emailOptions.UserName, password);
         await client.SendAsync(mimeMessage);

         client.Disconnect(true);
    }

     

    One thing, the FROM must be authorized to send emails. Actually, I only have the user administrator defined. Thus, when I used a fake email address such as "no-reply@mydomain.com", the code threw an exception:

     

    5.7.60 SMTP; Client does not have permissions to send as this sender 

     

    Hope this help someone.

     

     

    PatriceP
    Novice

    Re: Email configuration for Azure hosted web site

    Hello again,

     

    setting an alias to be used in the FROM field will resolve the exception when the FROM value is not a defined user.