duan47676379 2017-10-16 12:17
浏览 91

Swift Mailer - 异步发送电子邮件

on a project with intensive emailing activity we are creating asynchronnous workflow for posting emails. Workflow consists of 2 steps:

  1. creating the message (we set Subject, From, to, body, attachments), then converting to a string via $mailer->toString() and store into database.

  2. get few latest emails from database and send them out to user(s).

String stored into database is actually valid multipart EML file (e.g. can be open with Outlook) with message headers + body.

QUESTION:

How can I send message converted toString via SwiftMailer using it's transport capabilities?

Thank you.

Example of stored string in the database:

Message-ID: <1803a1a74c7612e43d58a8ca558117f3@refactoring.local>
Date: Mon, 16 Oct 2017 13:50:31 +0200
Subject: Sample subject
From: info@refactoring.local
Reply-To: info@refactoring.local
To: aaa@bbb.cc
MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="_=_swift_v4_1508154632_faf5d3b80866048d993d77a62a9e6497_=_"

--_=_swift_v4_1508154632_faf5d3b80866048d993d77a62a9e6497_=_
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

sample body ...

--_=_swift_v4_1508154632_faf5d3b80866048d993d77a62a9e6497_=_
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org=
/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml">
<head>
=09<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8"=
 />
=09<title>Sample title</title>
=09</head>
<body>
=09=09

=09sample body ...
=09</body>
</html>

--_=_swift_v4_1508154632_faf5d3b80866048d993d77a62a9e6497_=_--
  • 写回答

1条回答 默认 最新

  • dongxi3911 2017-10-16 12:32
    关注

    There's no simple way to convert a with toString serialized message back to an Swift_Message. Instead, you should use the serialize function to convert the Swift_Message you want to store inside the database back to an string.

    $data = serialize($message);
    // store inside database
    // ...
    // later..
    $message = unserialize($message);
    $mailer->send($message);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R