How to send a mail using ms graph api in laravel
How to Send Emails Using Microsoft Graph API in Laravel
In this post, you will be learning how to send an mail (Outlook Mail) using Microsoft MS Graph API in Laravel step by step.
Before sending any mail using MS Graph API, you have to get the "access token" of Microsoft Graph. (Here is the link - How to get access token using MS Graph API in Laravel)
We will be working on sending mail and also with BCC, CC, Attachments too.
Step 1: Create a Controller named MsGraphController.php and paste the below code to send mail using ms graph api.
Step 2: Create an API in following path: routes/api.php
Step 3: Input fields allowed to send a mail. you can also see these field in controller while validation.
- input name: to_email | Validation: Mandatory, Email only, string input. ( Eg: name="to_email" )
- input name: cc_emails | Validation: Not Mandatory, array input. ( Eg: name="cc_emails[]" )
- input name: bcc_emails | Validation: Not Mandatory, array input. ( Eg: name="bcc_emails[]" )
- input name: subject | Validation: Mandatory, string value, max 255 words. ( Eg: name="subject" )
- input name: body | Validation: Mandatory, string & html value. ( Eg: name="body" )
That's it. you are ready to use this functionality to get send mail using MS Graph API in Laravel with Access Token and use it as per your requirement in the frontend application like Vue Js, React Js, Angular, Nuxt, etc.