I am using this code snippet in an Apex Class, for sending mails:

Messaging.sendEmail( new Messaging.SingleEmailMessage[] { email } );

Is this possible to show the display name of the receiver (on toAddresses field) on the received mail?

Current result on received mail:

to: "firstName.lastName@gmail.com" < firstName.lastName@gmail.com>

Desired Result:

to: "firstName LastName" < firstName.lastName@gmail.com>

  • 2
    I guess it will be displayed first name and last name if to address added as contact in email – Ratan Paul Aug 30 '16 at 13:19
  • @Ratan I enter an email address of contact as a string on "SingleEmailMessage.setToAddresses". How can I add the address as contact? – user36922 Aug 30 '16 at 13:26
  • no if your to address is testTo@gmail.com and your from address is testfrom@gmail.com then open testTo@gmail.com gmail and add contact as testfrom@gmail.com and give any name. Try this once hope this work – Ratan Paul Aug 30 '16 at 13:29
  • I am looking for a programmatic global solution, so it will apply to all users without making changes on gmail. For the sender field, for example, we can use SingleEmailMessage.setSenderDisplayName method for showing the display name of the sender – user36922 Aug 30 '16 at 13:38

This functionality is not available, either on the Messaging.Email class (documentation) or the Messaging.SingleEmailMessage class (documentation). However, The setTargetObjectId method does seem to set it by default as FirstName LastName when sent to either a User or a Contact.

You have no control over the recipient display name in Apex.

| improve this answer | |
  • In your example, if you click on the arrow button, do you see your name on the list of the "to" addressees? Also, in my case, there can be more than one addressee, so I don't think that setTargetObjectId is suitable for me – user36922 Aug 30 '16 at 16:52
  • As for the display name...I actually was mistaken, and that was still the sender display name. – Adrian Larson Aug 30 '16 at 16:56

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.