Changing the from field on emails coming from SharePoint is one of the most requested things I’ve tripped across and while it’s certainly possible to achieve I haven’t found a good blog post showing or explaining how to do it. This post and the one to follow will detail two solutions to accomplish that: the first through javascript using the REST API and the second in a SharePoint 2013 workflow using the call http function.
REST API
First, I found this solution here:
http://sharepoint.stackexchange.com/questions/148226/send-e-mail-from-javascript-using-rest-api
function sendEmail(to, cc, bcc, from, body, subject) { var siteurl = _spPageContextInfo.webServerRelativeUrl; var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail"; $.ajax({ contentType: 'application/json', url: urlTemplate, type: 'POST', data: JSON.stringify({ 'properties': { '__metadata': { 'type': 'SP.Utilities.EmailProperties' }, 'From': from, 'To': { 'results': [to] }, 'CC': { 'results': [cc] }, 'BCC': { 'results': [bcc] }, 'Body': body, 'Subject': subject } }), headers: { 'Accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose', 'X-RequestDigest': jQuery('#__REQUESTDIGEST').val() }, success: function(data){ //alert('Email sent successfully'); }, error: function(data){ alert('Error in sending email: ' + JSON.stringify(data)); } }); }
Calling it is pretty easy.
sendEmail(to, cc, bcc, from, body, subject);
Keep in mind that to, cc, bcc and from must be a user like name@yourdomain.com, while body can contain html and subject must be a string.
The next post will show how to achieve the same thing though a 2013 workflow.