Send Email from Hotmail.com, Live.com, or Outlook.com
Question: I want my desktop application (or script) to send email from my Hotmail.com account (or my Live.com or Outlook.com account). My application will connect to the SMTP server for hotmail.com, authenticate using OAuth2, and send the email. I want to use Chilkat’s MailMan class to do it. I’m completely lost. Where do I even begin?
Answer: I fully understand why you are completely lost. It’s complicated and not well documented. Hopefully this blog post with links to sub-posts will clear things up.
First, let’s understand a few things:
-
- What are the SMTP server settings for hotmail.com, live.com, and outlook.com? See this: SMTP server settings for hotmail.com, live.com, and outlook.com
- Is Hotmail.com the same as Live.com?
- Is username@live.com the same email account as username@hotmail.com?
You’ll need to create an App Registration in Microsoft Entra ID (in the Azure Portal).
See this blog post for Creating an App Registration (OAuth2 Client ID) for OAuth2 Authentication for Hotmail.com, Live.com, or Outlook.com
You can see the Client ID under “Essentials”. It is labeled “Application (client) ID”
Now that you have an App Registration, which can be in a Microsoft account unrelated to your Hotmail.com account, you can run code to get an OAuth2 access token.
(As an aside: Think about how Mozilla Thunderbird does it. They have their own Azure App Registration, and use their Application (client) ID. When Thunderbird asks you for permission to access your account, you’ll login and then allow the access. This is exactly what you’ll be doing. Your app is the same as Mozilla Thunderbird, and doesn’t need to be related to the Hotmail.com, Live.com, or Outlook.com account you’re getting permission to access.)
Now that you have your App Registration setup, you can write code to get the initial OAuth2 access token. This will require a browser to be popped up to get the Hotmail.com account owner’s permission. However, once you have the initial access token, it can be refreshed over and over without user interaction.
Here are a few examples:
C# Hotmail OAuth2 Access Token for SMTP, IMAP, POP
Visual Basic 6.0 Hotmail OAuth2 Access Token for SMTP, IMAP, POP
Chilkat2-Python Hotmail OAuth2 Access Token for SMTP, IMAP, POP
C++ Hotmail OAuth2 Access Token for SMTP, IMAP, POP
Once you have the OAuth2 access token, you can send email.
Here are a few examples:
C# Send Email with hotmail.com, live.com, or outlook.com
Visual Basic 6.0 Send Email with hotmail.com, live.com, or outlook.com
Chilkat2-Python Send Email with hotmail.com, live.com, or outlook.com
C++ Send Email with hotmail.com, live.com, or outlook.com
Refreshing the Access Token
An OAuth2 access token is typically valid for 1 hour. Interaction with the Hotmail account owner via a browser is only needed for getting the initial access token. Once you have it, it can be continually refreshed without user interaction for a long time.
See: How Long can an OAuth2 Access Token be Refreshed?
Here are examples for refreshing the access token:
C# Hotmail Refresh Access Token (also for Live.com, Outlook.com)
Visual Basic 6.0 Hotmail Refresh Access Token (also for Live.com, Outlook.com)
Chilkat2-Python Hotmail Refresh Access Token (also for Live.com, Outlook.com)
C++ Hotmail Refresh Access Token (also for Live.com, Outlook.com)