daniel-zahariev / php-aws-ses

PHP classes that interfaces Amazon Simple Email Service
307 stars 100 forks source link

getRawMessage() Base64 Encoding #44

Closed Jimbob001 closed 7 years ago

Jimbob001 commented 7 years ago

Hi there,

Just got this up and running on a production server, works sweet as a nut, just a thought...

Could SimpleEmailServiceMessage -> getRawMessage() have an option for whether to do base64 encoding? Only when using the AWS SDK 3.X, the raw message is encoded for you, rather you needing to do it yourself. I'm currently decoding the output of getRawMessage to input to the SDK!

The basics of what I'm doing, this is an example of the Message object working with AWS's PHP SDK (so it uses all the IAM security) for those interested. This is inside another wrapper, hopefully the variable names are self explanatory.

        $this -> EmailMessage -> addTo($this -> SendTo);

        $this -> EmailMessage -> setFrom($SendFrom);
        $this -> EmailMessage -> setSubject($this -> Subject);

        $this -> EmailMessage -> setMessageFromString($this -> TxtData, $this -> Data);

        if (!$this -> EmailMessage -> validate()) {
        triggerError('Message failed validation.', E_USER_ERROR);
        }

        // My way of creating an AWS SDK client, not dissimilar to normal documented methods.
        $client = Enviro::get('AWS_SDK') -> createSES();
        $result = $client->sendRawEmail([
            'Destination' => [
                'ToAddresses' => $this -> SendTo
            ],
            'RawMessage' => [
                'Data' => base64_decode($this -> EmailMessage -> getRawMessage()) // This is the bit that seems a bit silly if it can be avoided
            ],
            'Source' => $SendFrom,
        ]);
daniel-zahariev commented 7 years ago

Thanks, there's now a parameter in the latest release.