Skip to main content

Hello,

I need to login to Office365 Outlook with OAuth2.0 for SMTP Protocol.
So far I cannot figure how this will be working and I am curious if anyone has already done something similar and is ready to share the connexion procedure ?

Thanks,



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hello,

I need to login to Office365 Outlook with OAuth2.0 for SMTP Protocol.
So far I cannot figure how this will be working and I am curious if anyone has already done something similar and is ready to share the connexion procedure ?

Thanks,



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hi, 

We have a service written to consume the MS Graph API to send mail, and access calendar entries. This uses the Oauth authentication. I have no experience in using UPOPMAIL with Oauth though. 

Regards, 
Iain



------------------------------
Iain Sharp
Head of Technical Services
Pci Systems Ltd
Sheffield GB
------------------------------

Hello,

I need to login to Office365 Outlook with OAuth2.0 for SMTP Protocol.
So far I cannot figure how this will be working and I am curious if anyone has already done something similar and is ready to share the connexion procedure ?

Thanks,



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Do you want to send an email or to authenticate users with their outlook profile.

Upopmail will send an email. I can give you some code.

If it's authentication then many moons ago I used ldap connector.

https://docs.rocketsoftware.com/bundle/uniface_104/page/mcs1665702735695.html



------------------------------
Osman Shariff
Freelance Uniface Consultant - France

Private message me if you need help with a project
English, French, German
------------------------------

Do you want to send an email or to authenticate users with their outlook profile.

Upopmail will send an email. I can give you some code.

If it's authentication then many moons ago I used ldap connector.

https://docs.rocketsoftware.com/bundle/uniface_104/page/mcs1665702735695.html



------------------------------
Osman Shariff
Freelance Uniface Consultant - France

Private message me if you need help with a project
English, French, German
------------------------------

Hello,


We already use Upopmail but Microsoft announced that they won't allow any more standard login (with user and password) on Outlook 365 and that only OAuth 2.0 authentification will be possible.
This is the reason we need to move and use the XOAUTH Driver.



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hello,


We already use Upopmail but Microsoft announced that they won't allow any more standard login (with user and password) on Outlook 365 and that only OAuth 2.0 authentification will be possible.
This is the reason we need to move and use the XOAUTH Driver.



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

A community sample published a while ago explains using the Xoauth driver with Microsoft - Community sample (XOAUTH). Is this what you are looking for?

Kind regards,

Mike



------------------------------
Michael Taylor
Rocket Internal - All Brands
------------------------------

A community sample published a while ago explains using the Xoauth driver with Microsoft - Community sample (XOAUTH). Is this what you are looking for?

Kind regards,

Mike



------------------------------
Michael Taylor
Rocket Internal - All Brands
------------------------------

Hello Mike,

Thanks a lot for pointing me to this Community Sample. It seems that it is what I am looking for and will be very helpful.



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

A community sample published a while ago explains using the Xoauth driver with Microsoft - Community sample (XOAUTH). Is this what you are looking for?

Kind regards,

Mike



------------------------------
Michael Taylor
Rocket Internal - All Brands
------------------------------

Hello,

I have got some issues to connect to Outlook365 via OAuth 2.0.

I am doing it as a batch application that runs on the server and send emails.
This is what I am doing:

TENANT_ID = "..."
CLIENT_ID = "..."
CLIENT_SECRET = "..."
vSCOPE = "https://outlook.office365.com/.default"

v_token_url = "https://login.microsoftonline.com/%%TENANT_ID%%%/oauth2/v2.0/token"

; Create a new HTTP request to get a token
newinstance "UHTTP", hUttp
hUttp->set_flags(15)
v_headers = ""
putitem/id/case v_headers, "Host", "login.microsoftonline.com"
putitem/id/case v_headers, "Content-Type", "application/x-www-form-urlencoded"
v_token_response = "client_id=%%CLIENT_ID%%%&client_secret=%%CLIENT_SECRET%%%&scope=%%vSCOPE%%%&grant_type=client_credentials"
hUttp->send(v_token_url, "POST", "", "", v_headers, v_token_response, v_response)

; Extract token from JSON
jsontostruct v_reply, v_token_response
v_access_token = v_reply->access_token
if v_access_token = ""
    putmess "Error: No token received"
endif

; Use UPOPMAIL
newinstance "UPOPMAIL", hPopmail

; Configure security UStartTLSSMTP
putmess "SetSecurity"
putitem/id v_sec_properties, "SMTP", "UStartTLSSMTP"
putitem/id v_sec_properties, "USE", "MAND"
hPopmail->SetSecurity(v_sec_properties, "")
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

; Configure security UAuthXOAUTH2SMTP
v_sec_properties = ""
putitem/id v_sec_properties, "SMTP", "UAuthXOAUTH2SMTP"
putitem/id v_sec_properties, "USE", "MAND"
putitem/id v_sec_parameters, "USER", "..."
putitem/id v_sec_parameters, "token", v_access_token
hPopmail->SetSecurity(v_sec_properties, v_sec_parameters)
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

putmess "logOnMail TLS"
; Connexion au serveur mail
hPopmail->logOnSMTP("tls:smtp.office365.com+587:pop_profile", "", "")
if $status < 0
    putmess "Erreur LogOnMail: %%$status"
endif

Here is the log that I get:
Upopmail
Non-DBMS file open error: /local/pmcu104/ydii_pmc/components/sig/upopmail.sig
Filesystem error:  #2 (No such file or directory)
Existence check: /app/uniface/yuni104/common/usys/sig does not exist.
Non-DBMS file open error: /local/pmcu104/ydii_pmc/components/sig/upopmail.sig
Filesystem error:  #2 (No such file or directory)
Non-DBMS file open error: /local/pmcu104/ydii_pmc/components/sig/upopmail.sig
Filesystem error:  #2 (No such file or directory)
UPOPMAIL: Version 10.4.02 005 20220909.160353
SetSecurity
UPOPMAIL: <F2> SETSECURITY: Setting security for SMTP protocol
UPOPMAIL: <D0> SETSECURITY: Driver SMTP=UStartTLSSMTP;USE=MAND: USEC_DRVINFO=USEC_SUCCESS: Initialised
UPOPMAIL: <F2> SETSECURITY: Setting security for SMTP protocol
UPOPMAIL: <D0> SETSECURITY: Driver SMTP=UAuthXOAUTH2SMTP;USE=MAND: USEC_DRVINFO=USEC_SUCCESS: Initialised
logOnMail TLS
UPOPMAIL: <F1> net_open: Opening connection with server: smtp.office365.com and port: 587:pop_profile
Existence check: /app/uniface/yuni104/common/usys/cacert.pem is a file.
NETERR_CONNECTION [-18]: TLS: [-10] Could not complete SSL handshake, (SSL: [1] SSL_ERROR_SSL OpenSSL error, (Client
Authenticating
Server) )
error:1408F10B:SSL routines:ssl3_get_record:wrong version number
UPOPMAIL: <E1> net_open: connection to server smtp.office365.com+587:pop_profile failed, status=-18
Erreur LogOnMail: -9

Is there anything that I am doing wrong ?

Thanks for your help,



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hello,

I have got some issues to connect to Outlook365 via OAuth 2.0.

I am doing it as a batch application that runs on the server and send emails.
This is what I am doing:

TENANT_ID = "..."
CLIENT_ID = "..."
CLIENT_SECRET = "..."
vSCOPE = "https://outlook.office365.com/.default"

v_token_url = "https://login.microsoftonline.com/%%TENANT_ID%%%/oauth2/v2.0/token"

; Create a new HTTP request to get a token
newinstance "UHTTP", hUttp
hUttp->set_flags(15)
v_headers = ""
putitem/id/case v_headers, "Host", "login.microsoftonline.com"
putitem/id/case v_headers, "Content-Type", "application/x-www-form-urlencoded"
v_token_response = "client_id=%%CLIENT_ID%%%&client_secret=%%CLIENT_SECRET%%%&scope=%%vSCOPE%%%&grant_type=client_credentials"
hUttp->send(v_token_url, "POST", "", "", v_headers, v_token_response, v_response)

; Extract token from JSON
jsontostruct v_reply, v_token_response
v_access_token = v_reply->access_token
if v_access_token = ""
    putmess "Error: No token received"
endif

; Use UPOPMAIL
newinstance "UPOPMAIL", hPopmail

; Configure security UStartTLSSMTP
putmess "SetSecurity"
putitem/id v_sec_properties, "SMTP", "UStartTLSSMTP"
putitem/id v_sec_properties, "USE", "MAND"
hPopmail->SetSecurity(v_sec_properties, "")
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

; Configure security UAuthXOAUTH2SMTP
v_sec_properties = ""
putitem/id v_sec_properties, "SMTP", "UAuthXOAUTH2SMTP"
putitem/id v_sec_properties, "USE", "MAND"
putitem/id v_sec_parameters, "USER", "..."
putitem/id v_sec_parameters, "token", v_access_token
hPopmail->SetSecurity(v_sec_properties, v_sec_parameters)
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

putmess "logOnMail TLS"
; Connexion au serveur mail
hPopmail->logOnSMTP("tls:smtp.office365.com+587:pop_profile", "", "")
if $status < 0
    putmess "Erreur LogOnMail: %%$status"
endif

Here is the log that I get:
Upopmail
Non-DBMS file open error: /local/pmcu104/ydii_pmc/components/sig/upopmail.sig
Filesystem error:  #2 (No such file or directory)
Existence check: /app/uniface/yuni104/common/usys/sig does not exist.
Non-DBMS file open error: /local/pmcu104/ydii_pmc/components/sig/upopmail.sig
Filesystem error:  #2 (No such file or directory)
Non-DBMS file open error: /local/pmcu104/ydii_pmc/components/sig/upopmail.sig
Filesystem error:  #2 (No such file or directory)
UPOPMAIL: Version 10.4.02 005 20220909.160353
SetSecurity
UPOPMAIL: <F2> SETSECURITY: Setting security for SMTP protocol
UPOPMAIL: <D0> SETSECURITY: Driver SMTP=UStartTLSSMTP;USE=MAND: USEC_DRVINFO=USEC_SUCCESS: Initialised
UPOPMAIL: <F2> SETSECURITY: Setting security for SMTP protocol
UPOPMAIL: <D0> SETSECURITY: Driver SMTP=UAuthXOAUTH2SMTP;USE=MAND: USEC_DRVINFO=USEC_SUCCESS: Initialised
logOnMail TLS
UPOPMAIL: <F1> net_open: Opening connection with server: smtp.office365.com and port: 587:pop_profile
Existence check: /app/uniface/yuni104/common/usys/cacert.pem is a file.
NETERR_CONNECTION [-18]: TLS: [-10] Could not complete SSL handshake, (SSL: [1] SSL_ERROR_SSL OpenSSL error, (Client
Authenticating
Server) )
error:1408F10B:SSL routines:ssl3_get_record:wrong version number
UPOPMAIL: <E1> net_open: connection to server smtp.office365.com+587:pop_profile failed, status=-18
Erreur LogOnMail: -9

Is there anything that I am doing wrong ?

Thanks for your help,



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hello,
Finally I found the correct version to have it work correctly.
This is what worked for me:

TENANT_ID = "..."
CLIENT_ID = "..."
CLIENT_SECRET = "..."
vSCOPE = "https://outlook.office365.com/.default"

v_token_url = "https://login.microsoftonline.com/%%TENANT_ID%%%/oauth2/v2.0/token"

; Create a new HTTP request to get a token
newinstance "UHTTP", hUttp
hUttp->set_flags(15)
v_headers = ""
putitem/id/case v_headers, "Host", "login.microsoftonline.com"
putitem/id/case v_headers, "Content-Type", "application/x-www-form-urlencoded"
v_token_response = "client_id=%%CLIENT_ID%%%&client_secret=%%CLIENT_SECRET%%%&scope=%%vSCOPE%%%&grant_type=client_credentials"
hUttp->send(v_token_url, "POST", "", "", v_headers, v_token_response, v_response)

; Extract token from JSON
jsontostruct v_reply, v_token_response
v_access_token = v_reply->access_token
if v_access_token = ""
    putmess "Error: No token received"
endif

; Use UPOPMAIL
newinstance "UPOPMAIL", hPopmail

; Configure security UStartTLSSMTP
putmess "SetSecurity"
putitem/id v_sec_properties, "SMTP", "UStartTLSSMTP"
putitem/id v_sec_properties, "USE", "MAND"
hPopmail->SetSecurity(v_sec_properties, "")
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

; Configure security UAuthXOAUTH2SMTP
v_sec_properties = ""
putitem/id v_sec_properties, "SMTP", "UAuthXOAUTH2SMTP"
putitem/id v_sec_properties, "USE", "MAND"
putitem/id v_sec_parameters, "USER", "..."
putitem/id v_sec_parameters, "token", v_access_token
hPopmail->SetSecurity(v_sec_properties, v_sec_parameters)
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

putmess "logOnMail TLS"
; Connexion au serveur mail
hPopmail->logOnSMTP("smtp.office365.com+587:pop_profile", "", "")
if $status < 0
    putmess "Erreur LogOnMail: %%$status"
endif

putmess "Sendmail"
hPopmail->SetFrom("...")
hPopmail->SetToList("...")
hPopmail->SetSubject("Hello World")
hPopmail->SetMessage("<strong>Hello World</strong>", "MIMEType=text/html")
hPopmail->Send("IgnoreRcptError=True")
putmess "Send result %%$status"



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hello,
Finally I found the correct version to have it work correctly.
This is what worked for me:

TENANT_ID = "..."
CLIENT_ID = "..."
CLIENT_SECRET = "..."
vSCOPE = "https://outlook.office365.com/.default"

v_token_url = "https://login.microsoftonline.com/%%TENANT_ID%%%/oauth2/v2.0/token"

; Create a new HTTP request to get a token
newinstance "UHTTP", hUttp
hUttp->set_flags(15)
v_headers = ""
putitem/id/case v_headers, "Host", "login.microsoftonline.com"
putitem/id/case v_headers, "Content-Type", "application/x-www-form-urlencoded"
v_token_response = "client_id=%%CLIENT_ID%%%&client_secret=%%CLIENT_SECRET%%%&scope=%%vSCOPE%%%&grant_type=client_credentials"
hUttp->send(v_token_url, "POST", "", "", v_headers, v_token_response, v_response)

; Extract token from JSON
jsontostruct v_reply, v_token_response
v_access_token = v_reply->access_token
if v_access_token = ""
    putmess "Error: No token received"
endif

; Use UPOPMAIL
newinstance "UPOPMAIL", hPopmail

; Configure security UStartTLSSMTP
putmess "SetSecurity"
putitem/id v_sec_properties, "SMTP", "UStartTLSSMTP"
putitem/id v_sec_properties, "USE", "MAND"
hPopmail->SetSecurity(v_sec_properties, "")
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

; Configure security UAuthXOAUTH2SMTP
v_sec_properties = ""
putitem/id v_sec_properties, "SMTP", "UAuthXOAUTH2SMTP"
putitem/id v_sec_properties, "USE", "MAND"
putitem/id v_sec_parameters, "USER", "..."
putitem/id v_sec_parameters, "token", v_access_token
hPopmail->SetSecurity(v_sec_properties, v_sec_parameters)
if $status < 0
    putmess "Erreur SetSecurity: %%$status"
    return
endif

putmess "logOnMail TLS"
; Connexion au serveur mail
hPopmail->logOnSMTP("smtp.office365.com+587:pop_profile", "", "")
if $status < 0
    putmess "Erreur LogOnMail: %%$status"
endif

putmess "Sendmail"
hPopmail->SetFrom("...")
hPopmail->SetToList("...")
hPopmail->SetSubject("Hello World")
hPopmail->SetMessage("<strong>Hello World</strong>", "MIMEType=text/html")
hPopmail->Send("IgnoreRcptError=True")
putmess "Send result %%$status"



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hi Stephane,

Can you please share your relevant asignment settings as well?

Kind regards,

Erik Spaltman 



------------------------------
Erik Spaltman
Waternet
Amsterdam NL
------------------------------


Hi Stephane,

Can you please share your relevant asignment settings as well?

Kind regards,

Erik Spaltman 



------------------------------
Erik Spaltman
Waternet
Amsterdam NL
------------------------------

Hi Erik,

There are the assignments that i added for this.
I haven't any assignment on the Certificate since I am using the default ca-bundle.crt in common/usys.

[DRIVER_SETTINGS]
USYS$TLS_PARAMS verify_server=yes, verify_server_name=no 

[NET_SETTINGS]
SrvCert         min_tls_version=1.3
USYS$TLS_PARAMS verify_server=1, verify_server_name=0

[USER_3GL]
<UnifaceInstallDirectory>/common/lib/uauthxoauth2(UAuthXOAUTH2POP, UAuthXOAUTH2SMTP)

Regards,

 



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------


Hi Erik,

There are the assignments that i added for this.
I haven't any assignment on the Certificate since I am using the default ca-bundle.crt in common/usys.

[DRIVER_SETTINGS]
USYS$TLS_PARAMS verify_server=yes, verify_server_name=no 

[NET_SETTINGS]
SrvCert         min_tls_version=1.3
USYS$TLS_PARAMS verify_server=1, verify_server_name=0

[USER_3GL]
<UnifaceInstallDirectory>/common/lib/uauthxoauth2(UAuthXOAUTH2POP, UAuthXOAUTH2SMTP)

Regards,

 



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hi Stephane,

Thanks a lot for your quick response.



------------------------------
Erik Spaltman
Waternet
Amsterdam NL
------------------------------

Hi Erik,

There are the assignments that i added for this.
I haven't any assignment on the Certificate since I am using the default ca-bundle.crt in common/usys.

[DRIVER_SETTINGS]
USYS$TLS_PARAMS verify_server=yes, verify_server_name=no 

[NET_SETTINGS]
SrvCert         min_tls_version=1.3
USYS$TLS_PARAMS verify_server=1, verify_server_name=0

[USER_3GL]
<UnifaceInstallDirectory>/common/lib/uauthxoauth2(UAuthXOAUTH2POP, UAuthXOAUTH2SMTP)

Regards,

 



------------------------------
Stephane Pfefer
Application Specialist
Darling
------------------------------

Hi Stephane,

I need to login to Office365 Outlook with OAuth2.0 for SMTP Protocol too.

I tried to implemants your solution but when it try to Logon SMTP it use the TCP protocol instead and i have the warning :

"Warning - Ignoring TLS profile ':Srv_Cert'  for the TCP connector" on my log files.

I tried lot of differents way to resolte it but nothing seems to work... Did you have any advice about that issue ?


I managed to recover the token with your solution but I don't understand why it's not necessary to identify yourself when recovering this token.

Regards, 



------------------------------
Jérémie CEDOLIN
Proges Plus
Willems FR
------------------------------