Friday, 21 August 2020

Using Swift Mailer messages with AWS SES API, but with streams

I'm trying to implement sending emails using the official AWS SDK for PHP, through AWS SES. I'm using php 7.2

My problem is with attachments. If I want to send attachments, I need to use the sendRawEmail method from the sdk. It accepts a Data key, than can be one of the following: <string || resource || Psr\Http\Message\StreamInterface>

Now, I am building my message using Swift_Message. This class has a toString() method than can be used to obtain the raw string of the email. Sending this raw string to the above sendRawEmail method works as expected and the email is successfully sent.

The problem with attachments is that, if we have a 5MB attachment, toString will generate a large string that will occupy memory. I would like to avoid this.

Swift_Message also has a toByteStream method that is able to write the message to a Swift_InputByteStream , but I have no idea how to use this with the AWS sdk and make sure that the string is streamed in chunks, in order to save memory.

Any help is appreciated. Thanks.



from Using Swift Mailer messages with AWS SES API, but with streams

No comments:

Post a Comment