function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jyovasjyovas 

From Address in Outbound Email

I have a Apex Scheduler class which will send out emails on nightly basis to designated compliance SMTP mail box.I want to set the "From" address of the email to be the user who created the record .I have the userId and can query the User objct and set the display name but not sure how to set the from address.

 

Is it possible?

 

Thanks for the help

-John

Jeremy-KraybillJeremy-Kraybill

Assuming you are using Messaging.sendEmail() to send the messages, they get the From: address set to the address of the user the code is running as, with apparently no way to override that. I would think System.runAs() would probably solve your problem, but remember that counts as a DML call in governor limits.

Afzal MohammadAfzal Mohammad

You may specify the address used when the recipients reply to the email.

 

mail.setReplyTo('support@example.com');

 

Hope that helps.

 

Afzal

ClaiborneClaiborne

system.runAs is only available in test metnods. It cannot be used in batch operations or any other classes except for test methods.