2016-06-01 6 views
0

私たちはSwiftmailerとMandrillを使って電子メールシステムを構築しました。本当に素晴らしいですが、今度はウェブフックを統合して、バウンス/失敗/失敗のアラートをトリガーしたいと考えています。Symfony2、Swiftmailer、Mandrill応答を取得

この時点で、送信された各メールに固有のIDを持つカスタムヘッダーを追加し、 Webhookが起動します。

これはうまくいきますが、私たちが使用できる_idを既に使用していますので、その上に別の一意のIDを追加しないようにしています。 symfonyのには、この応答を取り戻すためではSwiftMailerのいずれかの方法はあり

[ 
    { 
     "email": "[email protected]", 
     "status": "sent", 
     "reject_reason": "hard-bounce", 
     "_id": "abc123abc123abc123abc123abc123" 
    } 
] 

マンドリルのようなもので応答しますか? (後で使用するために_idを読み込んで保存できるように)

私はMandrillのphp SDKを使用できますが、Swiftmailerの使用を継続したいと考えています。 here

<?php 

include_once "swift_required.php"; 

$subject = 'Hello from Mandrill, PHP!'; 
$from = array('[email protected]' =>'Your Name'); 
$to = array(
'[email protected]' => 'Recipient1 Name', 
'[email protected]' => 'Recipient2 Name' 
); 

$text = "Mandrill speaks plaintext"; 
$html = "<em>Mandrill speaks <strong>HTML</strong></em>"; 

$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587); 
$transport->setUsername('MANDRILL_USERNAME'); 
$transport->setPassword('MANDRILL_PASSWORD'); 
$swift = Swift_Mailer::newInstance($transport); 

$message = new Swift_Message($subject); 
$message->setFrom($from); 
$message->setBody($html, 'text/html'); 
$message->setTo($to); 
$message->addPart($text, 'text/plain'); 

if ($recipients = $swift->send($message, $failures)) 
{ 
echo 'Message successfully sent!'; 
} else { 
echo "There was an error:\n"; 
print_r($failures); 
} 

?> 
+0

swiftmailerからメッセージを送信する際には、Mandatoryを使ってメッセージを送信する必要がありますその答えはおそらくそのパッケージのどこかにあるからです。 –

答えて

1

を説明したように私たちは、基本的ではSwiftMailerのインスタンスでSMTPトランスポートを使用している

EDIT 私はマンドリルは、SMTP経由でこの応答を渡すサポートとは思わない、あなたはそれのためのAPIを使用する必要があります。

例えば、accord/mandrill-swiftmailerにマンドリルからの応答を返すメソッドがあります:https://github.com/AccordGroup/MandrillSwiftMailer/blob/master/SwiftMailer/MandrillTransport.php#L215

あなたは、次のコードを使用マンドリルの応答を取得することができます:

$transport = new MandrillTransport($dispatcher); 
$transport->setApiKey('ABCDEFG12345'); 
$transport->setAsync(true); # Optional 
$response = $transport->getMandrillMessage($message); 
// $response now contains array with Mandrill's response. 

をあなたはSymfonuがaccord/mandrill-swiftmailer-bundleを使用して以降、それを統合することができます

$response = $mailer->getTransport()->getMandrillMessage($message); 
関連する問題