Send email using rest api using SharePoint online/2013/2016

his SharePoint tutorial, we will discuss how to send email using the rest API in SharePoint Online or SharePoint 2013/2013. Here we will be using Rest API, jQuery, and SP.Utilities.Utility js to send email in SharePoint.

Send email using rest api SharePoint Online

Here in this example, I have created a sample contact us HTML form. Here there will be three fields and a button. On click of the button, it will send the email.

Here I have added the below script to a web part page in a script editor web part in SharePoint Online or SharePoint 2013/2016.

<h1>Contact Us</h1><br/>
Name: <br/>
<input type="text" name="myname" id="myname" placeholder="Enter your Name"/><br/>
Email: <br/>
<input type="text" name="myemail" id="myemail" placeholder="Enter your Email Address"/><br/>
Message: <br/>
<textarea rows="4" cols="50" id="mymessage"></textarea><br/><br/>
<button type="button" id="fbutton">Send Message</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#fbutton").click(function(){
var sitetemplateurl = _spPageContextInfo.webServerRelativeUrl + "_api/SP.Utilities.Utility.SendEmail";
var name = $("#myname").val();
var from = $("#myemail").val();
var msg = 'From: ' + name + '<br/><br/>' + 'Email: ' + from + '<br/><br/><br/>' + $("#mymessage").val();

$.ajax({
contentType: 'application/json',
url: sitetemplateurl,
type: "POST",
data: JSON.stringify({
'properties': {
'__metadata': { 'type': 'SP.Utilities.EmailProperties' },
'From': from,
'To': { 'results': ['user1@OnlySharePoint2013.onmicrosoft.com'] },
'Body': msg,
'Subject':'New Email From SharePoint Online using RestAPI'
}
}),
headers: {
"Accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert('Message sent successfully !!!');
$("#myname").val(");
$("#myemail").val(");
$("#mymessage").val(");
},
error: function (err) {
alert(JSON.stringify(err));
}
});
});
});
</script>

Once save the page, the page will appear like below:

send email using rest api sharepoint 2013

After saving the page, after clicking on the button the email will go like below:

send email using rest api sharepoint online

You may like following SharePoint Rest API tutorials:

This SharePoint tutorial we learned how to send email using Rest API in SharePoint. The same Rest API code will work in SharePoint 2013/2016 to send an email.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

  • Ranjit Pokale says:

    Workaround for send an Email to Distribution list using JavaScript REST API in SharePoint?

  • Pawan says:

    Great post. Can we send outlook meeting request using rest API?

  • >