2017-10-16 98 views
0

對於密集電子郵件活動的項目,我們正在創建用於發送電子郵件的異步工作流程。工作流包括2個步驟:Swift Mailer - 異步發送電子郵件

  1. 創建消息(我們設定主題,發件人,於,正文,附件),然後經由$mailer->toString()轉換爲字符串,並存儲到數據庫中。

  2. 從數據庫中獲取少量最新電子郵件並將其發送給用戶。存儲到數據庫

字符串實際上是有效的多EML文件(例如可與Outlook打開)與消息頭+體。

問題:

我怎麼能發送郵件使用它的運輸能力,通過轉換的toString SwiftMailer?

謝謝。在數據庫中存儲的字符串的

例子:

Message-ID: <[email protected]> 
Date: Mon, 16 Oct 2017 13:50:31 +0200 
Subject: Sample subject 
From: [email protected] 
Reply-To: [email protected] 
To: [email protected] 
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_=_-- 

回答

0

有轉換帶toString連載消息發回的Swift_Message沒有簡單的方法。相反,您應該使用serialize函數將要在數據庫中存儲的Swift_Message轉換回字符串。

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

我們不需要將它轉換回來,當然:-)只是發送完全合格的有效電子郵件。我們擁有發佈所需的一切 - 「電子郵件」和SMTP授權憑證。以前使用PHPMailer的解決方案可以很方便地進行操作。我們正試圖從PHPMailer轉移到更符合RFC的庫。序列化絕對不是首選,因爲對象可能隨時改變。 – lubosdz