我正在使用 Amazon SES 服务。但是我不明白如何使用PHP跟踪退回的电子邮件并将这些电子邮件日志存储在数据库中。我有一个亚马逊博客的参考链接,但给出的解决方案是在 C#(http://sesblog.amazon.com/post/TxJE1JNZ6T9JXK/Handling-Bounces-and-Complaints) 上。需要帮助和帮助。谢谢。
为退回邮件和投诉创建一个SNS主题,并将其链接到您的SES(转到查看详细信息选项卡 - 编辑配置 - 链接相应的SNS投诉和退回邮件主题)。
确保根据您的要求将您创建的 SNS 主题订阅到您的邮件 ID 或 http/s。每当有退回邮件或投诉被标记为SES消息时,您都会收到一个JSON数据,稍后可以根据您的需要进行处理。
下面是一个非常有用的 AWS 网络研讨会:https://www.youtube.com/watch?v=n3Fr0bCsIvo
遵循的步骤
创建社交网络主题
创建订阅
确认订阅
法典
class AmazonController extends Controller
{
public function handleBounceOrComplaint(Request $request)
{
Log::info($request->json()->all());
$data = $request->json()->all();
if($request->json('Type') == 'SubscriptionConfirmation')
Log::info("SubscriptionConfirmation came at: ".$data['Timestamp']);
if($request->json('Type') == 'Notification'){
$message = $request->json('Message');
switch($message['notificationType']){
case 'Bounce':
$bounce = $message['bounce'];
foreach ($bounce['bouncedRecipients'] as $bouncedRecipient){
$emailAddress = $bouncedRecipient['emailAddress'];
$emailRecord = WrongEmail::firstOrCreate(['email' => $emailAddress, 'problem_type' => 'Bounce']);
if($emailRecord){
$emailRecord->increment('repeated_attempts',1);
}
}
break;
case 'Complaint':
$complaint = $message['complaint'];
foreach($complaint['complainedRecipients'] as $complainedRecipient){
$emailAddress = $complainedRecipient['emailAddress'];
$emailRecord = WrongEmail::firstOrCreate(['email' => $emailAddress, 'problem_type' => 'Complaint']);
if($emailRecord){
$emailRecord->increment('repeated_attempts',1);
}
}
break;
default:
// Do Nothing
break;
}
}
return Response::json(['status' => 200, "message" => 'success']);
}
}