You can’t specify the FROM address for email messages when you use the "Send an email" option from a SharePoint Designer 2013 workflow action


 

PROBLEM

When you create a SharePoint Designer 2013 Workflow and you use the Send an email action, you don't have the option to specify a FROM email address. This setting is pulled from the Outgoing Email settings in SharePoint 2013 on-premises Central Administration.

WORKAROUND

The SendEmail REST endpoint can be performed manually in a SharePoint Designer 2013 Workflow (also known as the SharePoint 2013 Workflow Platform) by using a valid SharePoint user's email address.
To understand what's being constructed, query the REST endpoint by using the SharePoint Designer Call HTTP Web Service Activity. Refer to the client-side object model (CSOM) documentation for more information. For more information, go to the following Microsoft website:

Utility.SendEmail method

This was performed on a SharePoint On-premise Site  
The following steps are used to re-create a parameterized version of what the Send an Email action does. Here's a sample JavaScript Object Notation (JSON) object sent by Workflow Manager to SharePoint 2013 by using the SharePoint REST endpoint:

{

"properties": {

"To": {

"results": ["i:0#.w|contoso\\validUser", "i:0#.w|contoso\\validUser2", "SharePoint Owner Group"]

},

"Subject": "HI",

"From": "validSPUser@contoso.com",

"__metadata": {

"type": "SP.Utilities.EmailProperties"

},

"Body": "<HTML><HEAD> <META name=GENERATOR content=\"MSHTML 10.00.9200.16843\"><\/HEAD>

<BODY> <P><FONT color=#00ff00 size=6 face=\"Segoe UI\"><STRONG><A href=\"Lists\/groups\/1_.000\">abc<\/A>

<\/STRONG><\/FONT><\/P><\/BODY><\/HTML>"

}

}

  1. Connect to a site by using SharePoint Designer 2013.
  2. Click Workflows, and then click Site Workflows.
  3. Give the workflow a name, and then select SharePoint 2013 Workflow Platform.
  4. Right-click the transition to stage, and then click go to stage.
  5. Click End of Workflow.
  6. Type replace to insert the replace action, and then click the first string text.
  7. Type a semicolon (;), and then in the second string, type a comma (,).
  8. Click the third string and then click Fx. Select Workflow Context, click Initiator, and then select Login Name as the return type. If multiple selections are enabled, you'll want to use the Login Names, Semicolon Delimited option.
    • This is an unnecessary step for a SharePoint People/Group column that has a single value. However, if you do this, it's possible to send email messages without additional changes to the workflow.
    • The output of this Replace action will be sent to a new variable called output.
  1. Insert another Replace action. This time, click the first string and then type a backslash (\). In the second string, type two backslashes (\\).
    • Select the variable named output as the data source from the previous step, and then change the output to the same step.
    • Doing this encodes the backslash that's found in SharePoint claims. Other characters may also have to be escaped.
  1. Insert a set workflow variable action. Set the output variable to use the output variable and several additional characters.
    • It should resemble the following:

[“[%Variable: output%]”]

    • Take the current value, which could be a single claim, multiple claims or SharePoint groups, and add quotation marks (") and square braces ([]) around it. The replace actions from before took the semicolon character and replaced it with a comma (,) and encoded any backslashes (\) with two backslashes (\\). Review the JSON object at the beginning of these steps to compare the patter that's being created manually.
  1. In Stage 1 type build, click Enter. This inserts the build a dictionary action.
  2. Click the Variable:Dictionary, and then create a new variable named requestBody. Leave it as a Dictionary Type.
  3. Click this variable, and then click the Add button.
  4. Click this variable, and in the dictionary variable properties, create the following key and value pairs:

 

Name

Type

Value

properties/__metadata/type

String

SP.Utilities.EmailProperties

properties/Subject

String

Hello

properties/From

String

validSPUser@contoso.com

properties/Body

String

HTML String.
This can be borrowed from a Send an Email action by right-clicking the action and then selecting properties and copying the HTML from the body. Any lookups that were performed will have to be redone.

properties/To/results

Dictionary

Perform a lookup by using the fx button, to the Workflow Variables and Parameters data source, select the output variable. The return type will be As Dictionary from JSON.

  1. Type build again, and then create another dictionary object. Create a new variable called requestheaders. The following key and value pairs have to be created:

Name

Type

Value

Accept

String

application/json; odata=verbose

Content-Type

String

application/json; odata=verbose

 

  1. Type Call, and then add the Call HTTP Web Service Action to the workflow.
  2. Click the workflow, and then in the dialog box, click the ellipses (...)
  3. Click Add or change lookup, click Workflow Context, click Current Site URL, and then click OK.
  4. After the lookup, type /_vti_bin/client.svc/sp.utilities.utility.SendEmail. It should resemble the following:

[%Workflow Context:Current Site URL%]/_vti_bin/client.svc/sp.utilities.utility.SendEmail

  1. Change HTTP Verb to HTTP POST, and then click OK.
  2. Click request, and then select the responseBody dictionary variable.
  3. Right-click Call HTTP Web Service Action and then click Properties. In the dialog box, select the RequestHeaders drop-down and thenspecify the requestHeaders variable. Click OK.
  4. Click Publish.
  5. Browse to /_layouts/15/start.aspx#/_layouts/15/workflow.aspx. The site workflow should be listed and when you the workflow name, it should send an email message that contains a custom FROM address.

MORE INFORMATION

Note These steps can be performed with a list or a reusable workflow. 
The FROM address has to be associated with a valid user in SharePoint.
The TO addresses also have to be valid SharePoint users. The same rules apply as if we used the Send an Email Action in SharePoint Designer 2013 on the SharePoint 2013 Workflow Platform.
The Call HTTP Web Service Action can be configured to output various data such as headers, response code, and response body. If a multiline column is created, the output of these variables can be written there. The log to history list isn't suitable as the response can be larger than 255 characters.

Note: This article is relevant to On-Premise version of SharePoint 2013

POST BY : Dalibor Kovacevic [MSFT]


Comments (19)

  1. Paul DeRouen says:

    Thanks for posting this,  When I attempt to build the first dictionary I don't have the dictionary json type for the properties/To/results key pair value.  I am selecting Output from the Workflow Variables and Parameters. Do you know what I may be doing wrong?

  2. Vish says:

    Hi Dalibor  – Thanks for the post.

    This workflow is working out fine but when users reply to the email from outlook, the reply-to address is no-reply@sharepoint.com

    Any ideas on making from and reply-to addresses same?

    Thanks in advance.

    1. David Remillard says:

      I also have this question. Specifically want to return Out Of Office autoreplies to the person specified in the Send field. I can change the Send field, but Return-Path is still “no-reply@blahblah.sharepoint.com”.

  3. Josh S. says:

    This is a huge shortcoming of SharePoint workflows.  I am glad you are posting a workaround but I really hope MSFT considers adding the ability to specify From and Reply To addresses in the built in Send Mail action.

  4. Andy says:

    Hey, is there a way that i can do this in sharepoint designer 2010?

  5. Stopped working says:

    Had this working on SharePoint Online, to include setting the return email, however recently it went to the no-reply email

    [%Workflow Context:Current Site URL%]/_api/sp.utilities.utility.SendEmail

    Any thoughts?

    1. Ariel says:

      Same here…however mine only stopped working about 3-4 weeks ago.

  6. Aria says:

    I get this error :
    Microsoft.Data.OData.ODataException” ‘PrimitiveValue’ node was found when reading from the JSON reader. A ‘StartArray’ node was expected.”}}}
    Any idea ?

  7. Dimitri Janssens says:

    Hi I have tried this workaround but for some reason this workflow doesn’t post any emails.
    It runs through the workflow with any issues, I checked the output variable on content and this seems to be okay.
    Any ideas how I can narrow down what or where my mistake lays?

  8. abhishek says:

    Visit the below URL for Rest operations like GET and POST
    https://abhisheksahayblog.wordpress.com/

  9. Sello_ says:

    Thank you so much. I simply followed your instructions and immediately it worked!

  10. sharifa says:

    I tried to implement it on list workflow , i am getting an error with building bodyrequest dictionary for the last item properties/To/results of dictionary type the error is :System.FormatException: The input source is not correctly formatted.

    i want to get the value of To / result from a column i have in my list called contact Email of string type .. can anyone help me with that issue. if for properties/To/results string fx to my column that have the email value its not give me error but no email revived as well

  11. Pete M says:

    Just got this working after several days. I kept getting ‘Bad Request’ response code. Output Response content and indications were that _metadata property was not recognised.
    THIS IS DOUBLE UNDERSCORE, why was this not pointed out! Anyway hope this helps somebody else save some time.

  12. Muhammad Arshad says:

    I have followed all steps as is found on REST API call workflow cancelled with below error:
    “RequestorId: 6a5862e1-6bd9-791e-316f-b345c90c990a. Details: System.ApplicationException: HTTP 500 {“Transfer-Encoding”:[“chunked”],”X-SharePointHealthScore”:[“0″],”SPClientServiceRequestDuration”:[“58″],”SPRequestGuid”:[“fdbdbff2-aefc-4d8f-9210-abdc14b850de”],”request-id”:[“fdbdbff2-aefc-4d8f-9210-abdc14b850de”],”X-FRAME-OPTIONS”:[“SAMEORIGIN”],”Access-Control-Allow-Origin”:XXXXXXXXX,”Access-Control-Allow-Credentials”:[“true”],”Access-Control-Allow-Headers”:[“Content-Type, X-HTTP-Method, X-RequestDigest, X-Custom-Header, X-PINGOTHER, Auth-Token,x-auth-token,X-Requested-With”],”Access-Control-Allow-Methods”:[“GET, POST, DELETE, OPTIONS”],”Access-Control-Max-Age”:[“1728000″],”X-Content-Type-Options”:[“nosniff”],”X-MS-InvokeApp”:[“1; RequireReadOnly”],”Cache-Control”:[“max-age=0, private”],”Date”:[“Thu, 22 Dec 2016 10:52:41 GMT”],”Server”:[“Microsoft-IIS\/8.5″],”X-AspNet-Version”:[“4.0.30319″],”X-Powered-By”:[“ASP.NET”]} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)”

    Anyone can help me to resolve this?

    1. Muhammad Arshad says:

      It failed on development server due to some CORS issue but worked on production server. But still one help need, how to post HTML body of email, when I used html either encoded UTF or ASCII or direct HTML workflow is not working.

  13. Sriram Eswaramoorthy says:

    Hello,

    I am confused with few steps. Can you post a screenshot of this workflow?

    With Regards,
    Sriram E

    1. Maicco says:

      The post is really useful but I am completely lost since you didn’t put any images to show us how to accomplish the steps like “Insert a set workflow variable action. Set the output variable to use the output variable and several additional characters”

      What do you mean when you say: “Set the output variable to use the output variable and several additional characters” ?
      I swear I read it at least 7 times and couldn’t get it.

      Thanks

  14. bart plessers says:

    Great article!
    Many thanx for sharing your knowledge.

    Bart

    1. szy says:

      Hi Bart, since you’ve been able to make it work, do you think you could share some print screens with us? Thanks!

Skip to main content