Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
650 views
in Technique[技术] by (71.8m points)

php - aws: ses with attach files

I use Laravel 4 framework with AWS sdk for SES. I am able to send regular emails using sendEmail function. I want to be able to attach files to the emails, the problem is that I can't find how to do it.

is it even possible to use sendEmail function to attach files or I must use send_raw_email function? (how to do this?)

this how I use SES:

$msg['Source'] = Config::get('mail.mailSource');
$msg['Destination']['ToAddresses'][] = $_GET['email'];
$msg['Message']['Subject']['Data']      = "bla bla";
$msg['Message']['Body']['Text']['Data'] = 'bla bla';
$msg['Message']['Body']['Html']['Data'] = 'bla bla';

$ses = AWS::get('ses');
$ses->sendEmail($msg);

I looked at AWS sdk in laravel and found there array with requirements for sendEmail function but there are no clues for attach files

'SendEmail' => array(
        'httpMethod' => 'POST',
        'uri' => '/',
        'class' => 'Aws\Common\Command\QueryCommand',
        'responseClass' => 'SendEmailResponse',
        'responseType' => 'model',
        'parameters' => array(
            'Action' => array(
                'static' => true,
                'location' => 'aws.query',
                'default' => 'SendEmail',
            ),
            'Version' => array(......
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the only way that I found to send emails with attachments (using SES SERVICE) is use SendRawEmail method.

  $message = "To: ". $_GET['email'] ."
";
            $message .= "From: ". $msg['Source'] ."
";
            $message .= "Subject: Example SES mail (raw)
";
            $message .= "MIME-Version: 1.0
";
            $message .= 'Content-Type: multipart/mixed; boundary="aRandomString_with_signs_or_9879497q8w7r8number"';
            $message .= "

";
            $message .= "--aRandomString_with_signs_or_9879497q8w7r8number
";
            $message .= 'Content-Type: text/plain; charset="utf-8"';
            $message .= "
";
            $message .= "Content-Transfer-Encoding: 7bit
";
            $message .= "Content-Disposition: inline
";
            $message .= "
";
            $message .= "Dear new tester,

";
            $message .= "Attached is the file you requested.
";
            $message .= "

";
            $message .= "--aRandomString_with_signs_or_9879497q8w7r8number
";
            $message .= "Content-ID: <77987_SOME_WEIRD_TOKEN_BUT_UNIQUE_SO_SOMETIMES_A_@domain.com_IS_ADDED>
";
            $message .= 'Content-Type: application/zip; name="shell.zip"';
            $message .= "
";
            $message .= "Content-Transfer-Encoding: base64
";
            $message .= 'Content-Disposition: attachment; filename="file.png"';
            $message .= "
";
            $message .= base64_encode( $attachedFile );
            $message .= "
";
            $message .= "--aRandomString_with_signs_or_9879497q8w7r8number--
";

            $sendMsg['RawMessage']['Data']         = (string)base64_encode($message);
            $sendMsg['RawMessage']['Source']       = $msg['Source'];
            $sendMsg['RawMessage']['Destinations'] = $_GET['email'];

            $ses->SendRawEmail($sendMsg);

pay attention to this rows:

$message .= 'Content-Disposition: attachment; filename="file.png"';

$message .= base64_encode( $attachedFile );


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...