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
Aviator517Aviator517 

Apex email replyto issue

I'm trying to send a basic email from apex, and have defined the "ReplyTo" to an address, but everytime I send a test email, the reply email is the email associated with my account.

 

Here is a bit of the code:

                Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();

                msg.setReplyTo('testemail@gmail.com');
                msg.setSenderDisplayName(displayName);
                msg.setToAddresses(new String[] {toAddress});
                msg.setSubject(subject);
                msg.setPlainTextBody(body);

                EmailList.add(msg);

 

Is there some quirk with the sandbox that doesn't allow the replyto email address to be assigned?

Best Answer chosen by Admin (Salesforce Developers) 
Aviator517Aviator517

I think I figured it out...needed to add the email as an org wide email address. I found this link helpful:

 

http://salesforce.stackexchange.com/questions/1243/setting-a-from-address-in-singleemailmessage