I can't figure out why an email isn't being sent. I've got a Platform Event trigger which ultimately is supposed to send an email. Most of the code isn't directly relevant, but here's the surrounding code, called by the trigger handler (cut down for demonstration):
public static void sendEmails() {
System.debug(Limits.getEmailInvocations());
Messaging.SingleEmailMessage sem = new Messaging.SingleEmailMessage();
sem.toAddresses = new List<String>{'myEmailAddress'};
sem.subject = 'testsubject';
sem.htmlBody = '<p>test Body</p>';
Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{sem});
System.debug(Limits.getEmailInvocations());
}
Debug:
20:22:26.0 (273270760)|USER_DEBUG|[47]|DEBUG|0
20:22:26.0 (346734155)|USER_DEBUG|[55]|DEBUG|1
Yet no email is received (not in Spam either). It's a sandbox, with Deliverability set to "All Email". No exceptions are thrown and I've tried my personal & work email addresses. When executing the Email send code above anonymously, it arrives in my inbox just fine.
EDIT: After further investigation, I've found the following in our server logs:
Our system has detected that this message is 550-5.7.1 not RFC 5322 compliant: 550-5.7.1 'From' header has non compliant domain name. 550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been 550-5.7.1 blocked.
So, now my question is...given that this is an Automated Process user and thus cannot be set to use an Org-Wide Email Address (there's no profile to enable on the address), how can I resolve this?
FROM
header at all.