5

I am trying to send an email to the user who initiated the event in the case of an error during event processing. In the subscriber I have code similar to the following:

public void onAfterInsert(Map<Id, my_event__c> events) {
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    email.setToAddresses(new string[]{'a@b.com'});
    email.setSaveAsActivity(false);
    email.setSubject('testing in subscriber...');
    email.setPlainTextBody('testing');

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


}

If the toAddress is a yahoo address, everything goes through just fine. If the email is a Gmail address (personal or corporate), it queues up to send just fine. However, it never gets delivered. I found this message in the Salesforce email logs:

"12/08/2017 19:50:47","37/C0-04567-71DEA2A5",P,"xxx@gmail.com","rsandoval=00df40000002czjeaq__8h38x9n2wlectxvw@nbughxf8745q.5b-vhtuam.cs52.bnc.sandbox.salesforce.com","173.194.205.27",1447,005f40000011pYR,"",0,"0.556447","reading confirmation",,,"550-5.7.1 [136.147.62.237 11] Our system has detected that this message is\r\n550-5.7.1 not RFC 5322 compliant:\r\n550-5.7.1 'From' header has non compliant domain name.\r\n550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been\r\n550-5.7.1 blocked. Please visit\r\n550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant\r\n550 5.7.1 and review RFC 5322 specifications for more information. u54si363262qte.264 - gsmtp"

I can send just fine with the exact same code to the same Gmail address in a normal trigger. In the log, it looks like this. Same exact sender as the failed message, but different remote host:

"12/12/2017 00:03:44","6D/72-04565-0EC1F2A5",R,"xxx@gmail.com","rsandoval=00df40000002czjeaq__s2xv7jhs06ggwtcp@rzt152b8j5n.5b-vhtuam.cs52.bnc.sandbox.salesforce.com","10.247.217.116",1263,005f40000011pYR,"",,,,,,

What would be different in the domain name when running as the Automated Process user? Is there a way around this so email can be sent to any domain?

  • Can you compare the 'From' header in the case where it works and Google rejects it? At a guess it might be something with the nbughxf8745q.5b-vhtuam.cs52.bnc.sandbox.salesforce.com domain name. – Daniel Ballinger Dec 10 '17 at 22:34
  • The successful message (to the same gmail address in a normal trigger) looks like this in the log. Same exact sender as the failed message. "12/12/2017 00:03:44","6D/72-04565-0EC1F2A5",R,"xxx@gmail.com","rsandoval=00df40000002czjeaq__s2xv7jhs06ggwtcp@rzt152b8j5n.5b-vhtuam.cs52.bnc.sandbox.salesforce.com","10.247.217.116",1263,005f40000011pYR,"<kg_v1000000000000000000000000000000000000000000000P0TMU800z44QnMh8RuqPGq-2gLKAbw@sfdc.net>",,,,,, – Rob Scott Dec 12 '17 at 0:29
  • I can't see it in the comment. Ideally edit the additional details back into the question. – Daniel Ballinger Dec 12 '17 at 0:30
  • 1
    Yeah. Sorry guess I can't put line breaks in comments. – Rob Scott Dec 12 '17 at 0:31
  • Hmm. I suspect you will need an internal Salesforce operations admin to decipher that. Do you have access to Premier Support? – Daniel Ballinger Dec 12 '17 at 1:12
5

We had a similar issue pertaining to email. What we found was that emails generated from Workflow were not reaching email addresses (specifically on the Gmail domain). Using the Email Log Files we determined that the sending user for emails sent by the Automated Process user was "rsandoval@ourorgid" with no ".com" appended. This meant that Gmail would ignore it and the email wasn't being delivered.

For this scenario the answer was to update the Email Alert's setting for "From Email Address" to use "Default Workflow User's email address" instead of "Current User's Email Address".

What is particularly interesting is that in each Org that uses the Automated Process user, the associated email is "Rsandoval@ourorgId". I'm guessing that "RSandoval" was the engineer that created the Automated Process global user when it was first created? Weird.

  • Your hypothesis seems correct about RSandoval being the engineer. But now I must know! – Mikey Mar 10 at 20:27

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.