Monday, 20 November 2017

Send mail using ajax calls

function SendEmailToBO(UsersToSendMail) {
   
    var urlTemplate = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Utilities.Utility.SendEmail",
    subject,
    body,
    fromEmail = 'abc@gmail.com';
    subject = "Project Created Successfully"
    body = "Hello,<br/><br/>Thank you for completing the Project Creation process.<br/><br/>The project created successfully .<br/> Project Name : "+ projectName  +" <br/> Project# : "+ no +" <br/>No further action is required on your part. For any queries/concerns, please contact Admin <br/><br/>Thank You<br/> Team.";


    $.ajax({
        contentType: "application/json; charset=utf-8",
        url: urlTemplate,
        type: "POST",
        dataType: "json",
        data: JSON.stringify({
            'properties': {
                '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
                'From': fromEmail,
'To': { 'results': UsersToSendMail },
                'Body': body,
                'Subject': subject
            }
        }),
        headers: {
            "Accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
         
                 
    },
        error: function (err) {          
            alert("Error @ SendEmail : " + err.responseText);
        }
    });
 
}