When sending emails via SP.Utilities.Utility.SendEmail, is it possible to change the From's display name so that it says something different rather than a title of the current site?
I'm fully aware of the fact that the from's email will always be no-reply@sharepointonline.com, but can I change the display name of it, at least?
Here is the code I'm using:
var subject = "SUBJECT OF THE MAIL";
var mailContent = "<h3>Some Heading for the mail</h3><p>Content</p><div>Content</div>";
var toList = ["usser5@contoso.onmicrosoft.com"]
//Send email message over REST
function sendMail(toList, subject, mailContent) {
var restUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.Utilities.Utility.SendEmail",
restHeaders = {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Content-Type": "application/json;odata=verbose"
},
mailObject = {
'properties': {
'__metadata': {
'type': 'SP.Utilities.EmailProperties'
},
'To': {
'results': toList
},
//'From': 'user@contoso.onmicrosoft.com"',
'FromDisplay': 'Display From"', // <--- I want a property like this one
// Important Note: this property does not work in SharePoint Online.
// the <from> field will always be "no-reply@sharepointonline.com"
'Subject': subject,
'Body': mailContent,
"AdditionalHeaders":
{
"__metadata":
{ "type": "Collection(SP.KeyValue)" },
"results":
[
{
"__metadata": {
"type": 'SP.KeyValue'
},
"Key": "content-type",
"Value": 'text/html',
"ValueType": "Edm.String"
}
]
}
}
};
return $.ajax({
contentType: "application/json",
url: restUrl,
type: "POST",
data: JSON.stringify(mailObject),
headers: restHeaders
});
}
$(function(){
sendMail(toList, subject, mailContent).then(function(data){console.log(data.d)})
})