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

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等