7

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();

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

            email.setSubject(subject);
            email.setHtmlBody(htmlBody);
            email.setPlainTextBody(plainBody);

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

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'));
}
else
{
    orgWideEmailAddressID = lstOrgWideEmailId[0].id;    
}
email.setOrgWideEmailAddressId(orgWideEmailAddressID);

This will help to solve issues in future.

0

Did you check this :

Setup->Administratration Setup->Deliverability

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

http://boards.developerforce.com/t5/Apex-Code-Development/setSenderDisplayName-isn-t-working-during-a-mass-email-send/td-p/221059

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 kumar Jun 21 '13 at 20:31
0

You can also see this blog very useful

http://www.codespokes.com/2013/08/how-to-send-email-from-apex-code-with.html

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.