Net talk email Oauth2 Step by Step for outlook, Code for Gmail. Yahoo not working!

This is a document of how I created an Oauth2 account with office365. It may not be 100% accurate. Give it a try if you have never tried to send email using Oauth2.

Setup outlook for Oauth2 and email

Register at this page. You will need to provide a credit card.

https://azure.microsoft.com/en-us/get-started/welcome-to-azure/

Start here

https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade

New Registration

Give it a name

Select the account type ( I chose multitenant

Redirect URL i chose web and http://localhost:8123

Click Register

Note - You should now see the application ID You will need this for your application

Click on the menu item Certificate & Secrets or Click on Add a Certificate or Secret on the right

Click on New Client Secret

Add a description

Select an expiration

Click ADD

You will see a value and secret ID. IMPORTANT! You want the VALUE and not the SECRET ID! you will use the VALUE as the secret id in NetTalk.

Click on the menu item API and permissions

Click on Add a permission

Click on Microsoft Graph

Click on Delegated permissions

( note there is a search for permissions. you will check two permissions )

Check offline_access
Check SMTP.Send

Click Add permissions

You should see your permissions added. Click on SMTP.Send

That should be it on the MS side.

The code for the OAuthParams is as follows

  clear(OAuthParms)
  OAuthParms.pServiceName    = 'Microsoft'
  OAuthParms.pOAuthVersion   = 2
  OAuthParms.pClientId       = glo:ClientIdOutlook ! 
  OAuthParms.pClientSecret   = glo:ClientSecretOutlook !
  OAuthParms.pRedirectURL    = 'http://localhost:8123'
  OAuthParms.pExternalBrowser = netOAuth:UseLocalBrowser
  OAuthParms.pListenTLS      = false
  OAuthParms.pListenPort     = 8123
  OAuthParms.pListenBindIP   = '127.0.0.1'      
  OAuthParms.pScope          = 'https://outlook.office.com/SMTP.send offline_access'
  OAuthParms.pAuthorizeURL   = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize'
  OAuthParms.pAccessTokenURL = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token'
  
  OAuthParms.pExpectedCertificateCommonName = 'stamp2.login.microsoftonline.com'    

Sending the email works as follows:

  EmailTo = glo:ToEmail
  EmailSubject = glo:ToEmailSubject
  EmailMessageText = glo:ToEmailMessageText  
  
  EmailFrom = glo:FromEmailOutlook
  EmailUser = glo:FromEmailOutlook      
  EmailServer          = 'smtp.office365.com'
  EmailPort            = 587 
  EmailPassword        = ''
  EmailToken           = OAuthParms.rToken
  EmailSSL             = TRUE
  EmailStartTLS        = TRUE

I would encourage anyone to try this out and please improve the documents where possible.

I also go gmail to work but I do not have the instructions for how to setup the gmail with google.

I can provide the code section.

Gmail OAuthParams:

  clear(OAuthParms)
  OAuthParms.pServiceName    = 'Google'
  OAuthParms.pOAuthVersion   = 2
  OAuthParms.pClientId       = glo:ClientIdGmail !Marathon 
  OAuthParms.pClientSecret   = glo:ClientSecretGmail !Marathon
  OAuthParms.pRedirectURL    = 'http://localhost:8123'
  OAuthParms.pExternalBrowser = netOAuth:UseLocalBrowser
  OAuthParms.pListenTLS      = false
  OAuthParms.pListenPort     = 8123
  OAuthParms.pListenBindIP   = '127.0.0.1'
  OAuthParms.pScope          = 'https://mail.google.com/'  
  OAuthParms.pAuthorizeURL   = 'https://accounts.google.com/o/oauth2/auth'
  OAuthParms.pAccessTokenURL = 'https://accounts.google.com/o/oauth2/token'

Gmail Email:

  EmailTo = glo:ToEmail
  EmailSubject = glo:ToEmailSubject
  EmailMessageText = glo:ToEmailMessageText  
  
  EmailFrom = glo:FromEmailGmail
  EmailUser = glo:FromEmailGmail      
  EmailServer          = 'smtp.gmail.com'
  EmailPort            = 587 
  EmailPassword        = ''
  EmailToken           = OAuthParms.rToken
  EmailSSL             = TRUE
  EmailStartTLS        = TRUE

I failed to get Yahoo to work. If anyone can help with this I would be very grateful.

Attempted OAuthParams:

  clear(OAuthParms)
  OAuthParms.pServiceName    = 'Yahoo'
  OAuthParms.pOAuthVersion   = 2
  OAuthParms.pClientId       = glo:ClientIDYahoo   
  OAuthParms.pClientSecret   = glo:ClientSecretYahoo
  OAuthParms.pRedirectURL    = 'https://falcon.mscflexone.com'
  OAuthParms.pExternalBrowser = netOAuth:UseLocalBrowser
  OAuthParms.pListenTLS      = false
  OAuthParms.pListenPort     = 8123
  OAuthParms.pListenPort     = 80
  OAuthParms.pListenBindIP   = '127.0.0.1'
  OAuthParms.pScope          = 'email'
  OAuthParms.pAuthorizeURL   = 'https://api.login.yahoo.com/oauth2/request_auth'
  OAuthParms.pAccessTokenURL = 'https://api.login.yahoo.com/oauth2/get_token'
  
  OAuthParms.pExternalBrowser = netOAuth:OnScreenHTML 

Email:

  EmailTo = glo:ToEmail
  EmailSubject = glo:ToEmailSubject
  EmailMessageText = glo:ToEmailMessageText  
  
  EmailFrom = glo:FromEmailYahoo
  EmailUser = glo:FromEmailYahoo      
  EmailServer          = 'smtp.mail.yahoo.com'
  EmailPort            = 587 
  EmailPassword        = ''
  EmailToken           = OAuthParms.rToken
  EmailSSL             = TRUE
  EmailStartTLS        = TRUE     

Jeff Hojka

2 Likes

These are the steps I tried to get yahoo email to work

Create an account at Yahoo

Go to the following link to create an app

Create Application

Give it a name and description

Homepage URL is optional

Redirect URL may not be local host

Chose Confidential Client

Check OpenID Connect Permissions

Select Email

Click Create App

Use the client ID and Client Secret in your application

1 Like