soto-project / soto

Swift SDK for AWS that works on Linux, macOS and iOS
https://soto.codes
Apache License 2.0
880 stars 83 forks source link

SotoSESV2 - Sending basic raw email rejected by google due to RFC 5322 compliance issue. How do i comply? #469

Closed bitwit closed 3 years ago

bitwit commented 3 years ago

I'm trying to send a raw email and while it successfully sends, Google is rejecting me due to compliance problems. The Soto API clearly works 🙏, but I can't figure out how to resolve this problem with google given the available parameters.

My code looks like this inside of my own SESManager class:

    func sendEmail(to: String, message: String) -> EventLoopFuture<Void> {

        guard let messageData = message.data(using: .utf8) else {
            return ses.eventLoopGroup.next().makeFailedFuture(SESError.messageNotUTF8)
        }

        return ses.sendEmail(
            SESV2.SendEmailRequest(
                content: .init(raw: .init(data: messageData)),
                destination: .init(toAddresses: [to]),
                fromEmailAddress: "hello@swiftuijam.com"
            )
        )
        .map { result in
            print(result)
            return ()
        }
    }

Google mailer-daemon rejects it back to the sender with

11] Our system has detected that this message is 
550-5.7.1 not RFC 5322 compliant: 
550-5.7.1 'From' header is missing. 
550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been 
550-5.7.1 blocked.
adam-fowler commented 3 years ago

It will be something to do with the contents of the raw email. It is probably missing a header, or a header is malformed. How are you generating this email?

I guess you'll need to look through your email and the rfc5322.

Here is an example of raw email sending working https://github.com/adam-fowler/ses-forwarder-lambda/blob/main/Sources/SESForwarder/main.swift. It takes emails sent to a SES managed domain and forwards them onto another email.

bitwit commented 3 years ago

Thank you! I think I have misinterpreted raw email to mean plain-text email. This makes a lot of sense.