1

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? enter image description here

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)})
})    
1

i am currently working on a similar problem and you can do it like this if you want to display a SharePoint user:

"properties" : {
    "__metadata": {
        "type": "SP.Utilities.EmailProperties"
    },
    "From": "username@domain", // <-- this one must be a SharePoint user 
    "Subject": "TestMail",
    "To": {
        "results": to
    },
    "Body": "Hallo Welt"
}

the result in outlook is the display name of the SharePoint User and <no-replay@sharepointonline.com> like the image below

enter image description here

And in an answer the to field will be the user.

| improve this answer | |
  • you are probably using SharePoint on-premises, right? In this case you can use the "from" field. in SharePoint Online it's ignored. – Denis Molodtsov Jan 20 '17 at 15:39
  • No, I am using SharePoint online. – G.Rite Jan 21 '17 at 20:23
  • so does it work? When you look at the message in Outlook, what does the "From" field say? – Denis Molodtsov Jan 23 '17 at 1:31
0

I'm concluding that in SharePoint Online it is impossible to use SP.Utilities.Utility.SendEmail method and specify the from field. From field will always be no-reply@sharepointonline.com and the Description will match the Title of the web site you are calling this method from.

| improve this answer | |
0

Thank to this answer, I found a way to change the From and the Reply also. I tested it with Sharepoint 2013 On-Promise:

{
  'properties': {
    '__metadata': {
      'type': 'SP.Utilities.EmailProperties'
    }
    'AdditionalHeaders': {
      "__metadata": {
        "type":"Collection(SP.KeyValue)"
      },
      "results": [
        {
          "__metadata": {
            "type": 'SP.KeyValue'
          },
          "Key": "From:",
          "Value": 'My Title <some.email@example.com>', // here you can change the From
          "ValueType": "Edm.String"
        },
        {
          "__metadata": {
            "type": 'SP.KeyValue'
          },
          "Key": "Reply-To:",
          "Value": 'email@example.com', // when the user will hit the Reply button, this email will be used
          "ValueType": "Edm.String"
        }
      ]
    },
    'To': {
      'results': [username]
    },
    'Body': body,
    'Subject': subject
  }
}
| improve this answer | |
  • I'm afraid the question was about SharePoint Online. This won't work in SPO. – Denis Molodtsov Nov 6 '19 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.