简体   繁体   中英

Swift Mailer - send emails asynchronnously

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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