0

I have a class that should look up a record, and send a Messaging.SingleEmailMessage with a certain template to a certain contact, and blind carbon copy some address.

The problem is that I'm not receiving an error message, even though Salesforce believes that the email is being sent.

I'm using Messaging.SendEmailResult to check if the message wasn't delivered, but to my surprise isSuccess() method returns true.

Using system.debug on the email message returns the following:

15:34:46:395 USER_DEBUG [37]|DEBUG|
    Messaging.SingleEmailMessage[
        getBccAddresses=(
            a_certain_email_address@gmail.com, another_certain_email_address@gmail.com
        );
        getCcAddresses=null;
        getCharset=null;
        getEntityAttachments=null;
        getFileAttachments=(
            Messaging.EmailFileAttachment[getBody=core.filemanager.ByteBlobValue@71ca58a7;
            getContentType=null;
            getFileName=FILE.pdf;
            getInline=false;
        ]);
        getHtmlBody=null;
        getInReplyTo=null;
        getOptOutPolicy=SEND;
        getOrgWideEmailAddressId=0D2o0000000PLQjCAO;
        getPlainTextBody=null;
        getReferences=null;
        getTargetObjectId=0034D0000072AI7QAM;
        getTemplateId=00X4D000000M97WUAS;
        getToAddresses=null;
        getWhatId=a0m4D000000ARVrQAO;
        isTreatBodiesAsTemplate=false;
        isTreatTargetObjectAsRecipient=true;
        isUserMail=false;
    ]

And on the send result:

15:34:46:682 USER_DEBUG [39]|DEBUG|(Messaging.SendEmailResult[getErrors=();isSuccess=true;])

Records are being created on the Activity History related list, and they show that the message was sent. But I never receive it.

  • I've checked Deliverability settings, and Access to Send Email is set to 'All email'.
  • I've checked my code, and every Id is valid, and the template page shows me the HTML email as expected, with no errors.
  • I've checked the SOQL being used to retrieve the records, no issue there too.
  • I've checked spam folders on Gmail, and nothing there either.

What can be wrong?

  • You've checked a lot of things on the Salesforce end, but have you checked your spam folders on the Gmail end? – Derek F May 23 '17 at 18:49
  • Yea, I have. Forgot to add that to the list. – Renato Oliveira May 23 '17 at 18:49
  • I didn't know you were able to combine target object with BCC. Are you sure that's allowed? – Adrian Larson May 23 '17 at 19:11
  • @AdrianLarson I think it is. But if it weren't, I'd probably get an error while trying to send the message, right? – Renato Oliveira May 23 '17 at 19:52
  • Did you enable enhance Email experience if so you can do an SOQL in EmailMessage object to inspect what is happening for success there should be a record. – Avijit Chakraborty May 23 '17 at 19:55
2

Have you checked your DKIM keys?

Yes I ha... oh, no. I have not.

Turns out that my Sandbox instance didn't have the DKIM keys used to sign emails sent through the platform. Meaning that the message would be flagged as sent, but would be blocked by Google's DMARC policy.

The solution was to copy the DKIM keys used in production.

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.