1

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('demo@gmail.com'); 
            conformemail.setSenderDisplayName('Ramesh');                 
            conformemail.setToAddresses(NEW String[]{'ramesh@gmail.com'});               
            Messaging.sendEmail(NEW Messaging.SingleEmailMessage[]{conformemail}); 
  • 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 '14 at 18:34
6

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');
  • 2
    I have remove as you specified line. Now it is working for me.... – Ramesh S Aug 20 '14 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.