2

How to override the from email address in the email.But in my code throw an exception.How to set the Organization-Wide email addresses.When I comment the code "setOrgWideEmailAddressId(owe.Id);"it send an email but From email address still displayed in email.

Exception:

 SendEmail failed. First exception on row 0; first error:
        DUPLICATE_SENDER_DISPLAY_NAME, 
        When an Org-Wide Email Address ID is specified, 
        a sender display name may not be specified.: []

I am unable to override the FROM EMAIL address. Some one can please help how to resolve the issue?

Actual code

OrgWideEmailAddress owe = [SELECT ID,IsAllowAllProfiles,DisplayName,Address FROM OrgWideEmailAddress WHERE IsAllowAllProfiles = TRUE LIMIT 1];

Messaging.SingleEmailMessage conformemail = NEW Messaging.SingleEmailMessage();
            conformemail.setSubject('Demo Subject');
            conformemail.setOrgWideEmailAddressId(owe.Id);
            conformemail.setHtmlBody('Demo Body');
            conformemail.setReplyTo('[email protected]'); 
            conformemail.setSenderDisplayName('Ramesh');                 
            conformemail.setToAddresses(NEW String[]{'[email protected]'});               
            Messaging.sendEmail(NEW Messaging.SingleEmailMessage[]{conformemail}); 
1
  • the error message seems clear - you can't mix setSenderDisplayName and setOrgWideEmailAddress on one SingleEmailMessage. I'm a little unclear as to what the problem is
    – cropredy
    Aug 19, 2014 at 18:34

1 Answer 1

7

As @crop1645 mentioned, the error message is fairly clear in this case. When you specify the Org-Wide Email Address you're sending the message from, you will not be able to also set the Sender Display Name. Your code example should work correctly after you remove this line:

conformemail.setSenderDisplayName('Ramesh');
1
  • 2
    I have remove as you specified line. Now it is working for me.... Aug 20, 2014 at 4:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .