반응형
Error executing "SendEmail" on "https://email.ap-northeast-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.ap-northeast-2.amazonaws.com` resulted in a `400 Bad Request` response:

  
    Sender
    MessageReje (truncated...)
 MessageRejected (client): Email address is not verified. The following identities failed the check in region AP-NORTHEAST-2: {메일주소} - 
  
    Sender
    MessageRejected
    Email address is not verified. The following identities failed the check in region AP-NORTHEAST-2: {메일주소}
  
  35c8331e-9efb-42a0-baab-97dcb5010bb9

The email was not sent. Error message: Email address is not verified. The following identities failed the check in region AP-NORTHEAST-2: {메일주소}​
composer require aws/aws-sdk-php

aws의 ses 서비스를 알게되고 php에서 메일을 발송하는 기능을 사용해보려고 한다.

 

ses 서비스를 이용해서 메일을 발송하면 도달율이 높고 속도가 굉장히 빠르다.

 

php의 내장함수인 mail을 사용하면 도달율이 낮고 발송되더라도 스팸메일함으로 분류될 가능성이 높다.

 

smtp 를 이용하면 속도가 좀 느린것 같다. 이 모든 문제점의 해결방안을 ses로 해결보고자 했다.

 

순서

1. ses 도메인 인증

2. sandbox 해제

3. composer 설치

4. iam 생성

5. 문제점 해결

6. 메일 발송 성공

 

 

1. 도메인 인증

Create Identity 버튼을 누르고 도메인 또는 이메일을 인증한다. 

 

도메인 인증에는 dns 레코드를 추가해야 하는데 aws의 route53을 이용하고 있으면 자동으로 추가 할 수 있다.

 

 

2. sandbox 해제

https://ap-northeast-2.console.aws.amazon.com/ses/home?region=ap-northeast-2#/account 

 

acount dashboard에 접속하면 상단의 Sandbox를 해제하라는 팝업창이 보인다.

 

send test mail 에서 메일이 발송되지 않아서 계속 찾던 중 sandbox가 문제라는것을 확인했다.

 

나도 아직 sandbox 해제 요청을 남긴 상태라 대기중이다.

 

3. composer 설치

composer require aws/aws-sdk-php

위 명령어를 통해 aws sdk를 설치해준다.

 

 

4. iam 사용자 추가 

https://ap-northeast-2.console.aws.amazon.com/ses/home?region=ap-northeast-2#/account 

 

account dashboard에서 smtp credential을 추가하면 iam 사용자가 생성된다.

 

https://us-east-1.console.aws.amazon.com/iamv2/home#/home

 

iam 서비스로 들어가서 사용자 > 추가된 사용자 > 보안자격증명 탭으로 가면 액세스키를 확인할 수 있다.

 

php에서는 .aws폴더의 credentials 파일에 저장해두면 된다.

 

 

5. 문제점 해결

Error executing "SendEmail" on "https://email.ap-northeast-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.ap-northeast-2.amazonaws.com` resulted in a `403 Forbidden` response:

  
    Sender
    SignatureDo (truncated...)
 SignatureDoesNotMatch (client): The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. - 
  
    Sender
    SignatureDoesNotMatch
    The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
  
  35474301-48e3-436a-bf89-15094e60d075

The email was not sent. Error message: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

위와 같이 나오면 자격증명이 실패한 상태이다.

 


$SesClient = new SesClient([
    'profile' => 'ses',
    'version' => '2010-12-01',
    'region'  => 'ap-northeast-2'
]);

profile과 credentials 파일의 사용자명을 동일하게 입력, region은 내가 ses를 추가한 지역을 설정해준다.

 


[ses]
aws_access_key_id = 
aws_secret_access_key =

credentials 파일은 위와 같이 작성해줬다.

 

 


Error executing "SendEmail" on "https://email.ap-northeast-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.ap-northeast-2.amazonaws.com` resulted in a `400 Bad Request` response:

  
    Sender
    MessageReje (truncated...)
 MessageRejected (client): Email address is not verified. The following identities failed the check in region AP-NORTHEAST-2: [메일]
  
    Sender
    MessageRejected
    Email address is not verified. The following identities failed the check in region AP-NORTHEAST-2: [메일]
  
  35c8331e-9efb-42a0-baab-97dcb5010bb9

The email was not sent. Error message: Email address is not verified. The following identities failed the check in region AP-NORTHEAST-2: [메일]

위와 같이 뜨면 샌드박스를 해제해야한다.

 

6. 메일 성공

메일이 성공되면 해당 메시지를 확인할 수 있다.

 

<?php
error_reporting(-1);
ini_set('display_errors', 1);

require 'vendor/autoload.php';

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

/*echo '<pre>';
$SesClient = new Aws\Ses\SesClient([
    'profile' => 'default',
    'version' => '2010-12-01',
    'region' => 'ap-northeast-2',
    'credentials' => [
        'key'    => 'AKIAQPTXDULNRMIY5ELU',
        'secret' => 'BLwqdcKHKezeskU/5O/JhjpyAFDTMuptIl9rmYcYBcXP'
    ]
]);

$domain = 'comepage.me';

try {
    $result = $SesClient->verifyDomainIdentity([
        'Domain' => $domain,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}*/

echo '<pre>';
// Create an SesClient. Change the value of the region parameter if you're
// using an AWS Region other than US West (Oregon). Change the value of the
// profile parameter if you want to use a profile in your credentials file
// other than the default.
$SesClient = new SesClient([
    'profile' => 'ses',
    'version' => '2010-12-01',
    'region'  => 'ap-northeast-2'
]);

// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
$sender_email = '';

// Replace these sample addresses with the addresses of your recipients. If
// your account is still in the sandbox, these addresses must be verified.
$recipient_emails = [''];

// Specify a configuration set. If you do not want to use a configuration
// set, comment the following variable, and the
// 'ConfigurationSetName' => $configuration_set argument below.
$configuration_set = 'ses-configuration-set';

$subject = 'Amazon SES test (AWS SDK for PHP)';
$plaintext_body = 'This email was sent with Amazon SES using the AWS SDK for PHP.' ;
$html_body =  '<h1>AWS Amazon Simple Email Service Test Email</h1>'.
    '<p>This email was sent with <a href="https://aws.amazon.com/ses/">'.
    'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">'.
    'AWS SDK for PHP</a>.</p>';
$char_set = 'UTF-8';

try {
    $result = $SesClient->sendEmail([
        'Destination' => [
            'ToAddresses' => $recipient_emails,
        ],
        'ReplyToAddresses' => [$sender_email],
        'Source' => $sender_email,
        'Message' => [
            'Body' => [
                'Html' => [
                    'Charset' => $char_set,
                    'Data' => $html_body,
                ],
                'Text' => [
                    'Charset' => $char_set,
                    'Data' => $plaintext_body,
                ],
            ],
            'Subject' => [
                'Charset' => $char_set,
                'Data' => $subject,
            ],
        ],
        // If you aren't using a configuration set, comment or delete the
        // following line
        'ConfigurationSetName' => $configuration_set,
    ]);
    $messageId = $result['MessageId'];
    echo("Email sent! Message ID: $messageId"."\n");
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo("The email was not sent. Error message: ".$e->getAwsErrorMessage()."\n");
    echo "\n";
}

위 메일 발송 소스에서 메일주소만 변경하여 발송해보자.

 

 

 

 

 

반응형

+ Recent posts