【问题标题】:Get Error Code For Unverified Identities In SendMail Exception AWS SES PHP SDK在 SendMail 异常 AWS SES PHP SDK 中获取未验证身份的错误代码
【发布时间】:2016-11-08 13:56:17
【问题描述】:

我目前正在捕获未使用以下代码验证身份的异常 -

use Aws\Ses\SesClient;
use Aws\Ses\Exception;

try {
       $result = $ses->sendEmail($data);
} catch (Exception $e) {

    echo $e->getResponse();

}

它打印出以下内容 -

PHP Fatal error:  Uncaught exception 'Aws\Ses\Exception\SesException' 
with message 'Error executing "SendEmail" on "https://email.us-
west-2.amazonaws.com"; AWS HTTP error: Client error: `POST 
https://email.us-west-2.amazonaws.com` resulted in a `400 Bad Request` 
response:

<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
    <Error>
    <Type>Sender</Type>
    <Code>MessageReje (truncated...)
    MessageRejected (client): Email address is not verified. The 
following identities failed the check in region US-WEST-2: 
arn:aws:ses:us-west-2:**************** - <ErrorResponse 
xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
    <Error>
    <Type>Sender</Type>
    <Code>MessageRejected</Code>
    <Message>Email address is not verified. The following identities 
failed the check in region US-WEST-2: arn:aws:ses:us-
west-2:************</Message>
    </Error>
  <RequestId>*****************</RequestId>
</ErrorResponse>

exception 'GuzzleHttp\Exception\ClientException' with  in /var/www
/html/data/aws/Aws/WrappedHttpHandler.php on line 159

我无法使用下一页概述的任何方法来打印出任何不同的东西 -

http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Ses.Exception.SesException.html

有什么想法可以从这个异常中得到一个实际的错误代码,以便我可以在脚本的其余部分采取适当的操作吗?

【问题讨论】:

  • 您确定您使用的是正确的命名空间吗? Aws\Ses\Exception\SesException 显示在文档中。您可能希望将异常命名为 @Dekel 提示的别名。由于您正在命名Aws\Ses\Exception,因此您可以尝试捕获SesException 并在那里处理它。

标签: php amazon-web-services amazon-ses


【解决方案1】:

为了捕捉你最好使用的所有异常

} catch (\Exception $e) {

为了确保您不会从错误的命名空间中获得错误的 Exception 类。

关于您遇到的问题 - 使用 Amazon SES 发送电子邮件时,您必须首先使用 verify your email/domain(请注意,如果未经验证,任何 From, source, sender, return-path 标头都可能导致您出现问题)。

如果您可以发布一些关于您的 $ses 对象或 $data 的信息,您使用它可能会有所帮助。

【讨论】:

    【解决方案2】:

    Class MessageRejectedException 表示操作失败,无法发送消息。检查错误堆栈以获取有关导致错误的原因的更多信息。

    Exception
        Extended by RuntimeException
            Extended by Aws\Common\Exception\RuntimeException implements Aws\Common\Exception\AwsExceptionInterface
                Extended by Aws\Common\Exception\ServiceResponseException
                    Extended by Aws\Ses\Exception\SesException
                        Extended by Aws\Ses\Exception\MessageRejectedException
    

    试试这个 -> 使用 Aws\Ses\Exception\MessageRejectedException; 或使用 Aws\Ses\Exception\SesException;并将类名替换为 catche 块

    因为 Aws\Ses\Exception 是 MessageRejectedException 类的命名空间。 您必须使用带有命名空间的类,而不仅仅是命名空间。

    use Aws\Ses\SesClient;
    use Aws\Ses\Exception\MessageRejectedException;
    
    try {
           $result = $ses->sendEmail($data);
    } catch (MessageRejectedException $e) {
    
        echo $e->getResponse();
    
    }
    

    我希望有所帮助。 祝你好运

    【讨论】:

      【解决方案3】:

      你可以使用$e-&gt;getAwsErrorCode();

      从 Aws\Exception\AwsException 继承的方法 __construct()__toString()get()getAwsErrorCode()getAwsErrorMessage()getAwsErrorShape()getAwsErrorType()getAwsRequestId()getCommand()getRequest()getResponse()getResult()getStatusCode()getTransferInfo()hasKey()isConnectionError()isMaxRetriesExceeded()search()setMaxRetriesExceeded()setTransferInfo()

      您可以在这里看到来自 AWS 的 SesExeption API 链接:https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Ses.Exception.SesException.html

      【讨论】:

        猜你喜欢
        • 2022-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-19
        • 1970-01-01
        • 2012-10-12
        • 2020-04-15
        • 1970-01-01
        相关资源
        最近更新 更多