Ask Search:
Willy OppenheimWilly Oppenheim 

How to dynamically change 'from' address in email alert?

Hello all,

I know how to change the 'from' address in an email alert using organization-wide emails, but I am wondering if it is possible to dynamically change this address in a workflow.  We are dynamically populating an email field on SF records and would like to trigger an email alert in which this dynamically-generated email is the 'from' address.  How do you advise we proceed?  I have read about some possible solutions via Apex, VisualForce, and MarketingCloud, but I am not sure what is the easiest or best way forward.  Note: the dynamically generated email addresses will all be on our own email domain.

Background info:  My team is implementing an email relay feature so that when a customer receives an email from us (sent via SF), the customer can reply to the email and it will push the data back to SF.  This requires the customer to be writing to a uniquely generated email address like reply123@omprakash.org.  We have written the script which creates the unique email addresses and pushes the data from the unique email address to the relevant record in SF.  Now we just need to figure out how to have this unique email address be the 'from' address for the initial email we are sending them.  


Thank you!

Willy
Best Answer chosen by Willy Oppenheim
Steve SclarSteve Sclar
Super easy with visualforce. George posted the solution, which just requires converting the applicable html email templates to visualforce templates:
https://salesforce.stackexchange.com/questions/34739/using-custom-field-value-in-replyto-attribute-of-messagingemailtemplate

All Answers

Stephen NoeStephen Noe
Based on what you've described I would say you best solution would be to implement this with an Apex trigger. While this does require custom development, this will give a solution to meet your requirements and deliver that in a scalable way. Your Apex trigger would contain the business logic for when your email message should be sent and then dynamically build your email message. Here are some articles to help you get started:
Willy OppenheimWilly Oppenheim
Stephen, thanks so much for your input.  Before we go down the road of doing this via Apex, I'm wondering if there's a way to do it by using the 'reply to' fxn in Visualforce.  For example, I found this thread on StackExchange which seems promising -- https://salesforce.stackexchange.com/questions/34739/using-custom-field-value-in-replyto-attribute-of-messagingemailtemplate -- but I don't fully understand it.  Can you provide any further clarity?

Thank you!

Willy
Stephen NoeStephen Noe
Although "visualforce" is in the title of this, the question nor the suggested solution refer to using visualforce.

The suggested solution is saying a custom formula field could be used to handle the logic to determine your From address. However, it doesn't reference how then to use that custom field.

I would still suggest doing this Apex. 
Willy OppenheimWilly Oppenheim
Ok, thank you very much!
Steve SclarSteve Sclar
Super easy with visualforce. George posted the solution, which just requires converting the applicable html email templates to visualforce templates:
https://salesforce.stackexchange.com/questions/34739/using-custom-field-value-in-replyto-attribute-of-messagingemailtemplate
This was selected as the best answer