如何从 Amazon SES 检索响应?

Posted

技术标签:

【中文标题】如何从 Amazon SES 检索响应?【英文标题】:How to retrieve response from Amazon SES? 【发布时间】:2014-07-12 21:09:21 【问题描述】:

我有验证 Amazon ses 中电子邮件地址的代码

<?php
$sesClient = SesClient::factory(array(
            'key'    => 'secret key',
            'secret' => 'secret',
            'profile' => 'user_name',
            'region'  => 'us-east-1'
        ));
$result = $sesClient->verifyEmailAddress(array('EmailAddress'=> $email));
?>

我的 $result 输出是这样的:

object(Guzzle\Service\Resource\Model) 
    [protected] structure => null
    [protected] data => array()

我实际上在我指定的电子邮件 ID 中收到了经过验证的电子邮件。我的问题是,如何使用我收到的回复检查该功能是否正常工作?在早期的亚马逊网络服务中,他们使用$result-&gt;is('Ok') 来验证结果。我现在应该使用什么函数来检查该函数的成功和失败结果?

我已经检查了amazon link,但仍然找不到成功响应的功能

【问题讨论】:

问题:如果您尝试验证电子邮件地址 lolcat@example 又名无效的电子邮件地址会怎样?你得到什么回应? @Michael 我收到了这个回复object(Guzzle\Service\Resource\Model) [protected] structure =&gt; null [protected] data =&gt; array() 如果您使用有效的电子邮件地址,您会收到不同的回复吗? 所以,似乎 data->ResponseMetaData->RequestId 将在成功时设置而在错误时丢失... @RobertHarvey 对于每个电子邮件地址的问题,无论其有效性如何,我都会得到相同的回复 【参考方案1】:

我相信你需要使用verifyEmailIdentity 不是 verifyEmailAddress:

$result = $sesClient->verifyEmailIdentity(array('EmailAddress'=> $email));

如 AWS 文档中所述:

VerifyEmailAddress 操作自 5 月起已弃用 2012 年 15 月 15 日发布域验证。验证电子邮件身份 现在首选行动。

Further Reading

【讨论】:

感谢您的建议。现在如何检查邮件是否发送给特定订阅者?正如我在问题中指定的那样,亚马逊用 $result->is('Ok') 替换了什么功能? @Ganesh,据我了解,verifyEmailIdentityResult 以空结果响应,确认请求已成功完成。它似乎是VerifyEmailIdentity 的一部分,是从VerifyEmailIdentityResponse 返回的。唯一提到这一点的似乎是我链接的两个网址;我注意到的类文档没有提及它。【参考方案2】:

查看 aws-sdk-php 的测试发现:

https://github.com/aws/aws-sdk-php/blob/master/tests/Aws/Tests/Ses/Integration/IntegrationTest.php#L86

也许你可以试试:

$sesClient->verifyEmailAddress(array('EmailAddress'=> $email));
$sesClient->waitUntilIdentityExists(array('Identities' => array($email)));
$result = $sesClient->getIdentityVerificationAttributes(array('Identities' => array($email)));
if ('Success' === $result->getPath("VerificationAttributes/$email/VerificationStatus"))

【讨论】:

以上是关于如何从 Amazon SES 检索响应?的主要内容,如果未能解决你的问题,请参考以下文章

Amazon API - 检索产品描述

Amazon SES 返回的 SMTP 响应代码 530

iOS 检索 Web 响应数据后如何从 JSON 中检索值

Amazon SES 电子邮件地址未验证

如何从响应改造中检索 cookie,okhttp?

如何从 SOAP 响应中检索元素值