繁体   English   中英

Swift Mailer-异步发送电子邮件

[英]Swift Mailer - send emails asynchronnously

在具有大量电子邮件活动的项目中,我们正在创建异步工作流来发布电子邮件。 工作流程包括2个步骤:

  1. 创建消息(我们设置了主题,从,到,正文,附件),然后通过$mailer->toString()转换为字符串并存储到数据库中。

  2. 从数据库中获取很少的最新电子邮件,并将其发送给用户。

存储到数据库中的字符串实际上是有效的多部分EML文件(例如,可以使用Outlook打开),带有消息标题+正文。

题:

我如何使用SwiftMailer的传输功能来发送转换为String的消息?

谢谢。

数据库中存储的字符串示例:

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_=_--

没有简单的方法将带有toString序列化消息转换回Swift_Message 相反,您应该使用serialize函数将要存储在数据库中的Swift_Message转换回字符串。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM