Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

outlook 365 OAuth2

trial03

Technical User
Oct 9, 2011
16
MY
Hi master,

Microsft Exchange Online will permanently remove support for Basic authentication with Client Submission (SMTP AUTH) in September 2025.



Could anyone provide a vfp sample to send mail by 365 OAuth2?

Thanks and best regards,
 
Trial03,

My single advice to you is to acquire the Chilkat API.

Examples regarding the use of OAuth2 with VFP: https://www.example-code.com/foxpro/oauth2.asp.
Dear Sir,

I appreciate your input. It is very helpful.

Before acquire the Chikat Api. Would you mind sharing a sample code and explaining how to set it up in Azure? I just want to make sure I understand the process, as I'm not a professional, and I cant find a direct VFP msOffice oAuth2 sample in the link https://www.example-code.com/foxpro/oauth2.asp.

Thanks and Regards,
 
1747203462180.png
2nd and 3rd Example on the page.

Sorry, I can't help you with the full process, as I don't have Azure at my disposal and I won't register there just to guide you through the processes necessary within Azure (registering an app, for example).

The whole authorization process could be much simpler, if you use a Mail client and automate it via MAPI.
 
I just want to make sure I understand the process, as I'm not a professional
How far are you involved in writing code for the FoxPro application? If you're not a programmer, you won't settle this without programming a new feature, you can't just change a few options or settings and be done with this.
 
Last edited:
View attachment 2238
2nd and 3rd Example on the page.

Sorry, I can't help you with the full process, as I don't have Azure at my disposal and I won't register there just to guide you through the processes necessary within Azure (registering an app, for example).

The whole authorization process could be much simpler, if you use a Mail client and automate it via MAPI.
 
Dear Sir,

Thanks for reply.

I already read the 2nd and 3rd Example on the page, but lack of eMail sending by using https://graph.microsoft.com/v1.0/users/{sender}/sendMail.

I try follow the

GMail SMTP Send using Previously Obtained OAuth2 Access Token

but it is not working with the error :

SMTP XOAUTH2 authentication
  • Your JWT is issued for Microsoft Graph API ("aud":"https://graph.microsoft.com"), but you're trying to authenticate with Outlook SMTP (smtp.office365.com) which requires a token issued for https://outlook.office365.com.
  • You're using client credentials flow, which does not work with SMTP unless very specific conditions are met (and it's extremely limited).





  • Now try figure out how to send it by using https://graph.microsoft.com/v1.0/users/{sender}/sendMail or workable method.
    Hopefully can get a sample code for VFP + msOffice365 oAuth2 for sending email.
    Thanks and regards,






 
The answer is in the error message, isn't it? You need a token issued for https://outlook.office365.com


Regarding using graph API: As far as I googled and learned MS graph API allows you to send a mail on behalf of one user. You can't use Graph to simply send an email with any sender to Exchange via code. It's therefore not really a "Send-Mailmessage" replacement, if you want to use it that way.

On the other hand, if you don't need your code to be able to send mails on behalf of any Exchange account you also only need Graphs mail sending method and that announcement wasn't about a change of Graph.

Taking it from my alltime experience with multiple organisations including a mail feature in their FoxPro applications, all they ever needed was sending mail on behlaf of the application user. That means sending mails for all employees of the company, but each only for them. You don't need that general access, usually.

>You're using client credentials flow
That points out you want to send mail for one user. Well, then you bark up the wrong tree. Did you actually used this up to now and did authentication stop working?
 
Last edited:
Dear
The answer is in the error message, isn't it? You need a token issued for https://outlook.office365.com


Regarding using graph API: As far as I googled and learned MS graph API allows you to send a mail on behalf of one user. You can't use Graph to simply send an email with any sender to Exchange via code. It's therefore not really a "Send-Mailmessage" replacement, if you want to use it that way.

On the other hand, if you don't need your code to be able to send mails on behalf of any Exchange account you also only need Graphs mail sending method and that announcement wasn't about a change of Graph.

Taking it from my alltime experience with multiple organisations including a mail feature in their FoxPro applications, all they ever needed was sending mail on behlaf of the application user. That means sending mails for all employees of the company, but each only for them. You don't need that general access, usually.

>You're using client credentials flow
That points out you want to send mail for one user. Well, then you bark up the wrong tree. Did you actually used this up to now and did authentication stop working?
Dear Sir,

Finally I found out a good sample in https://www.example-code.com/foxpro/outlook_send_email_with_attachments.asp. and it is working.

Sharing this in case it’s helpful —who program that sends emails using Microsoft 365.

Thanks for the help and best regards,
 
Okay, fine, that goes with what I said, earlier

The whole authorization process could be much simpler, if you use a Mail client and automate it via MAPI.
You're just not using MAPI. If users have a dektop version of Outlook installed, you're also still able to automate Outlook.Application:
Code:
oOutlook = CreateObject("Outlook.Application")
There's a nice FAQ about how to send mail and use many more features of Outlook based on this COM automation server:

If CreateObject("Outlook.Application") doesn't work, then that's unlikely just a bad installation (could be) but more likely a sign the Outlook365 version they use is not the normal automatiable desktop version and you're good to go with what you found.

The major point, though, if you just want to send a mail, it's far easier to automate a mail client than signing in to a mail server and handling mail by SMTP. You get rid of all the authentication steps with the Outlook desktop client automation, unless they configured login to their Mail account in Outlook. Usually automating Outlook you're in the main Outlook account with the Outlook.Application object.
 
And on a more general level: I can understand such announcements make people nervous. Whether it initially was you or someone from your customer's company pointing that out. They just see "mail" and know their application mails, so they conclude they'll be affected. If smtp authentication is new to you, then you're not using it now, and that's most likely because up until now you're also juat autmating mail composition and sending it. It's the job of a mail client to connect to a mail server and that's Outlook, no matter what Office, whether it's desktop Outlook, "Outlook New", OWA, the Outlook of Office365 or other Office versions. Unless you explicitly program to connect to a mail server, which is an Exchange server, as the backbone of a Microsoft based architecture of Workstations and Servers with Office, you don't have to care for changes of authantication, as you're not doing that, whatever mail client they use does that and also is changed with updates and knows how to do that. Mail client configuration is usually not the job of us software develeopers, unless you would explicitly write a mail client software, usually you're just asked to automate mail sending, it's rare you're asked to process incomiong mail and also other features like appointments.

Regading Outlook tha automation server options is becoming more and more obsolete, though it's usually an option witin the same subscription model companyies use to have Office on their workstations, the desktop application suite is still the best for us to add features of automation, like also creating Word documents, Excel Sheets with data, with or without formulas that expand their usability, and more. It's always good to advise them to use that suite, if they want features like that.

And last not least how this works using Graph was posted by @wOOdy-Soft in this post: https://www.tek-tips.com/threads/cl...application-is-not-found.1833801/post-7587932

So you might get this going (using the right access token and this recipe) using Graph, too.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top