问题描述
我将Laravel 4框架与适用于SES的AWS开发工具包结合使用.我可以使用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'] ."\n";
$message .= "From: ". $msg['Source'] ."\n";
$message .= "Subject: Example SES mail (raw)\n";
$message .= "MIME-Version: 1.0\n";
$message .= 'Content-Type: multipart/mixed; boundary="aRandomString_with_signs_or_9879497q8w7r8number"';
$message .= "\n\n";
$message .= "--aRandomString_with_signs_or_9879497q8w7r8number\n";
$message .= 'Content-Type: text/plain; charset="utf-8"';
$message .= "\n";
$message .= "Content-Transfer-Encoding: 7bit\n";
$message .= "Content-Disposition: inline\n";
$message .= "\n";
$message .= "Dear new tester,\n\n";
$message .= "Attached is the file you requested.\n";
$message .= "\n\n";
$message .= "--aRandomString_with_signs_or_9879497q8w7r8number\n";
$message .= "Content-ID: \<77987_SOME_WEIRD_TOKEN_BUT_UNIQUE_SO_SOMETIMES_A_@domain.com_IS_ADDED\>\n";
$message .= 'Content-Type: application/zip; name="shell.zip"';
$message .= "\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= 'Content-Disposition: attachment; filename="file.png"';
$message .= "\n";
$message .= base64_encode( $attachedFile );
$message .= "\n";
$message .= "--aRandomString_with_signs_or_9879497q8w7r8number--\n";
$sendMsg['RawMessage']['Data'] = (string)base64_encode($message);
$sendMsg['RawMessage']['Source'] = $msg['Source'];
$sendMsg['RawMessage']['Destinations'] = $_GET['email'];
$ses->SendRawEmail($sendMsg);
请注意以下行:
$ message.='Content-Disposition:附件; filename ="file.png"';
$ message.= base64_encode($ attachedFile);
这篇关于AWS:带有附件的ses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!