Freigeben über


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

  • Anonymous
    June 02, 2015
    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?

  • Anonymous
    June 22, 2015
    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.

    • Anonymous
      June 07, 2017
      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".
  • Anonymous
    June 23, 2015
    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.

  • Anonymous
    September 06, 2015
    Hey, is there a way that i can do this in sharepoint designer 2010?

  • Anonymous
    January 29, 2016
    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?

    • Anonymous
      April 15, 2016
      Same here...however mine only stopped working about 3-4 weeks ago.
  • Anonymous
    April 24, 2016
    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 ?

  • Anonymous
    May 01, 2016
    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?

  • Anonymous
    May 18, 2016
    Visit the below URL for Rest operations like GET and POST https://abhisheksahayblog.wordpress.com/

  • Anonymous
    July 03, 2016
    Thank you so much. I simply followed your instructions and immediately it worked!

  • Anonymous
    November 29, 2016
    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

    • Anonymous
      May 02, 2018
      Hi Sharifa, did you manage to find solution to your problem? Regards
  • Anonymous
    December 06, 2016
    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.

  • Anonymous
    December 22, 2016
    The comment has been removed

    • Anonymous
      December 22, 2016
      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.
  • Anonymous
    February 07, 2017
    Hello,I am confused with few steps. Can you post a screenshot of this workflow?With Regards,Sriram E

    • Anonymous
      March 03, 2017
      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
  • Anonymous
    May 17, 2017
    Great article!Many thanx for sharing your knowledge.Bart

    • Anonymous
      June 19, 2017
      Hi Bart, since you've been able to make it work, do you think you could share some print screens with us? Thanks!
  • Anonymous
    June 26, 2018
    Nice article, thanks :))