aws:带有附加文件的 ses [英] aws: ses with attach files
问题描述
我使用 Laravel 4 框架和 AWS sdk for SES.我可以使用 sendEmail 功能发送常规电子邮件.我希望能够将文件附加到电子邮件中,问题是我找不到如何去做.
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.
是否可以使用 sendEmail 函数来附加文件,或者我必须使用 send_raw_email 函数?(如何做到这一点?)
is it even possible to use sendEmail function to attach files or I must use send_raw_email function? (how to do this?)
这就是我使用 SES 的方式:
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);
我在 laravel 中查看了 AWS sdk 并发现有对 sendEmail 函数有要求的数组,但没有附加文件的线索
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(......
推荐答案
我发现发送带附件的电子邮件(使用 SES SERVICE)的唯一方法是使用 SendRawEmail 方法.
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);
注意这一行:
$message .= '内容处理:附件;filename="file.png"';
$message .= base64_encode( $attachedFile );
这篇关于aws:带有附加文件的 ses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!