We are using the Single email message class to send emails on a forgot user name scenario. We want to change the from address display name to a valid name. I used the email.setSenderDisplayName method and override the name and still salesforce is overriding it with a custom name. How do we set the display name to a valid name? This is happening on a force.com site and for the guest user profile. I could not use the organization wide email address as salesforce does not show the guest user profile on the drop down.

here is the code

            Messaging.Singleemailmessage email = new Messaging.Singleemailmessage();

            orgName = UserInfo.getOrganizationName();
            apexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'sender display name'+ String.valueOf(orgName ) ));
            email.setToAddresses(new String[] { emailTo });


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

I fixed this. The solution is that to create an organization wide email address and set it to all profiles which would work for guest user profile as well. On the code , just call the following

List<OrgWideEmailAddress> lstOrgWideEmailId = [Select id from OrgWideEmailAddress];
if(lstOrgWideEmailId.size() == 0)
   throw(new PkException('There is no Organization wide email address setup in the org. Please set the organization wide email address'));
    orgWideEmailAddressID = lstOrgWideEmailId[0].id;    

This will help to solve issues in future.


Did you check this :

Setup->Administratration Setup->Deliverability

UnCheck checkbox: Enable compliance with standard email security mechanisms Enable Sender ID compliance


Is this set up correct?

  • Yes, i unchecked the sender compliance but it still shows the username who created the site. It still does not work. Does anybody know where the apex code is looking for to display the senderdisplay name? – Buyan Thyagarajan Jun 21 '13 at 20:31

You can also see this blog very useful


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.