You need to sign in to do that
Don't have an account?
goabhigo
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.
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
Hi abhi,
have a look at the .setSenderDisplayName() and .setReplyTo() method.
Cheers!
Martin
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 !!!
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
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.