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
goabhigogoabhigo 

Set fromAddress in Email

Hi,

 

Is there anything similar to mail.setToAddresses(str) [which sets the recipient's email addresses] to set the sender's address, like setFromAdresses(str) ?

 

I am sending email through Apex trigger.

 

for(Travel_Reimbursement__c tr : Trigger.New) {
        mail = new Messaging.SingleEmailMessage();
        toAddress = new String[] {ownerMap.get(tr.OwnerId).Manager.Email}; 
        mail.setToAddresses(toAddress);
        mail.setSenderDisplayName(ownerMap.get(tr.OwnerId).Name);
        //mail.fromAddress();  ??????       
        mail.setSubject('Request for approval of Travel Reimbursement-'+tr.CreatedDate.format('M/d/yyyy'));
        mail.setPlainTextBody('Test');
        mail.setHtmlBody('<h2>Travel Reimbursement</h2>');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

 Everything works fine. But when I check that email in my inbox, it shows different address(of admin).

 

 

Please suggest.

 

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

Not a 100%, but reckon you set up Org wide email addresses to be used as a From address in Workflow email alerts and possible Apex outbound email.

 

This article seems to illustrate how you can select the right outbound email address

http://blog.sforce.com/sforce/2009/08/practical-org-wide-address-usage.html

All Answers

HaagenHaagen

Hi abhi,

 

have a look at the .setSenderDisplayName() and .setReplyTo() method.

 

Cheers!

 

Martin

goabhigogoabhigo

Thanks for the reply Haagen, but both doesn't solve my problem.

I have already used .setSenderDisplayName(), which shows the name which I want to display but the email address shown is of admin's !!!

Ritesh AswaneyRitesh Aswaney

Not a 100%, but reckon you set up Org wide email addresses to be used as a From address in Workflow email alerts and possible Apex outbound email.

 

This article seems to illustrate how you can select the right outbound email address

http://blog.sforce.com/sforce/2009/08/practical-org-wide-address-usage.html

This was selected as the best answer
goabhigogoabhigo

Thanks Ritesh.

That solved my problem after some RND and trouble shooting.

I am able to send from address according to the rquirement.

 

A great article by Quinton Wall.