I want to set a from address in a salesforce SingleEmailMessage, but can't see a way to do this and there is no standard method described in the documentation.
I want the email to be sent from [email protected], however, the email address of the user editing the record (which triggers the email send) is used as from address.
I'm using the following code:
mail.setReplyTo(fromaddress);
mail.setSenderDisplayName(fromaddress);
But my code only changes the display name, not the email address.
Full code:
public static void sendSingleMail(id objId, ID templateId, string fromaddress) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setReplyTo(fromaddress);
mail.setTemplateId(templateId);
mail.setTargetObjectId(objId);
mail.saveAsActivity = false;
mail.setReplyTo(fromaddress);
mail.setSenderDisplayName(fromaddress);
ErrLogger.logger('Email being sent to :');
ErrLogger.logger('objId found: ' + objId);
ErrLogger.logger('templateId found: ' + templateId);
ErrLogger.logger('fromaddress found: ' + fromaddress);
Messaging.sendEmail(new Messaging.SingleEmailmessage[] {mail});
}