Sending Mails Using REST

The mail sending process is a POST method and so it uses a metadata content which is to be passed with different parameters as shown below.

The metadata includes the Sender’s and recipient’s email addresses along with the Subject and body of the mail.

function Mail(){
$.ajax({
contentType: ‘application/json’,
url: “https://sitename/_api/SP.Utilities.Utility.SendEmail”,
type: “POST”,
data: JSON.stringify({
‘properties’: {
‘__metadata’: { ‘type’: ‘SP.Utilities.EmailProperties’ },
‘From’: ‘Sender’s email address’,
‘To’: { ‘results’: [‘recipient’s Email address’] },
‘Body’: ‘<h1>Hello!!</h1><p>This is mail was sent from a client side function</p>’,
‘Subject’:’Send eMail’
}
}
),
headers: {
“Accept”: “application/json;odata=verbose”,
“content-type”: “application/json;odata=verbose”,
“X-RequestDigest”: $(“#__REQUESTDIGEST”).val()
},
success: function (data) {
alert(“eMail sent successfully.”);
},
error: function (err) {
alert(JSON.stringify(err));
}

});
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s