You need to sign in to do that
Don't have an account?

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
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.
You may specify the address used when the recipients reply to the email.
mail.setReplyTo('support@example.com');
Hope that helps.
Afzal
system.runAs is only available in test metnods. It cannot be used in batch operations or any other classes except for test methods.