douxi6903 2014-05-23 12:25
浏览 127
已采纳

aws:带附件的ses

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(......
  • 写回答

2条回答 默认 最新

  • dougeqiang1619 2014-06-30 10:06
    关注

    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 );

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向