drsl90685154 2017-12-05 08:25
浏览 21
已采纳

如何创建swiftmailer消息并将其附加到另一条消息

We are using SwiftMailer in one of our functions who sends emails out. At the end, there is a general report sent to the department manager in order to keep trace and be informed about the function usage.

The manager is now willing to also receive a copy of the email sent out, we could do this by adding one email copy as attachment to the email report.

Any idea on how can we create a swiftmailer message and not sending it, only using it as attachment for a new swiftmailer email.

  • 写回答

1条回答 默认 最新

  • dongshungou7699 2017-12-05 16:00
    关注

    You could add your Swift_Message as an attachment like this:

    $attachment = new \Swift_Attachment($messageAttachment, 'some-email.txt', 'text/plain');
    

    However, your email would be now attached as an .txt file which contains all mail details. I'm not sure if this is the expected behaviour!?

    Full example:

    $messageAttachment = (new \Swift_Message('Attached Email'))
        ->setFrom('yourmail@gmail.com')->setTo('yourmail@gmail.com')
        ->setBody("Attached Email Body", 'text/plain');
    $attachment = new \Swift_Attachment($messageAttachment, 'some-email.txt', 'text/plain');
    
    $message = (new \Swift_Message('Real Email'))
        ->setFrom('yourmail@gmail.com')->setTo('yourmail@gmail.com')
        ->setBody("Real Email Body", 'text/plain')
        ->attach($attachment);
    $mailer->send($message);
    

    The content of the attached some-email.txt will look like this:

    Message-ID: <568d128d97e530d1389cb83b154d64eb@swift.generated>
    Date: Tue, 05 Dec 2017 17:00:05 +0100
    Subject: Attached Email
    From: yourmail@gmail.com
    To: yourmail@gmail.com
    MIME-Version: 1.0
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: quoted-printable
    
    Attached Email Body
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab