Skip to content


How to send Email to Microsoft Online Services using SMTP Relay

Today I was trying to write PowerShell to inform me when a user had been migrated to Online Services. The best way to do this was to use PowerShell and write a script to send me an email once the migration had completed. Unfortunately, the samples on the net didn’t work and Microsoft Online Services support stated that the supported way was:

  • To connect to the Microsoft Online Services SMTP server, open your SMTP client application and provide the information below.
  • The fully qualified domain name (FQDN) of the Microsoft Online Services SMTP server. The FQDN will be slightly different depending on which Microsoft Online Services datacenter your company is connected to. The server FQDNs are:
    • Americas Datacenter: Smtp.mail.microsoftonline.com
    • Europe Datacenter: Smtp.mail.emea.microsoftonline.com
    • Asian / Pacific Datacenter: Smtp.mail.apac.microsoftonline.com
    • The user name and password of a Microsoft Online Services user account with an Exchange Online license.
      On most client applications, this is under “My outgoing mail server (SMTP) requires authentication” – this should be configured “Yes”, and the corresponding Microsoft Online username and password supplied.
    • The SMTP port to use: 587.
      On most client applications, this is under “Server Port Numbers for Outgoing Server (SMTP)” – this should be configured to use port 587
    • Make sure that Transport Layer Security (TLS) is enabled in your SMTP client.
      On most client applications, this is under “My outgoing mail server (SMTP) requires an encrypted connection (SSL)” – this should be configured “Yes”
      NOTE: The FROM address must use a SMTP domain of type “Authoritative” – this can be confirmed in Microsoft Online Administration Console, under the Users – Domains tab.
      Important: Remember to update the user Microsoft Online Account password regularly, before it expires.”
    • ADDITIONAL INFO:
      The address that you should use for SMTP access is: "smtp.mail.microsoftonline.com". Make sure you use your user name and password for you account if it asks for the information. On most client applications, this is under “My outgoing mail server (SMTP) requires authentication” – this should be configured “Yes”, and the corresponding Microsoft Online username and password supplied.
    • The SMTP port to use: 587.
      NOTE: The FROM address must use a SMTP domain of type “Authoritative” – this can be confirmed in Microsoft Online Administration Console, under the Users – Domains tab.

    It took me ages to get it right, but here’s a working script:

    $EmailFrom = "Email Sender"
    $EmailTo = "Recipient"
    $Subject = "message subject"
    $Body = "messageBody"
    $SMTPServer = "smtp.mail.apac.microsoftonline.com"
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password");
    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

    Posted in BPOS, Microsoft, Online Services.


    0 Responses

    Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



    Some HTML is OK

    or, reply to this post via trackback.