2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EC-CUBE4 Amazon SES を利用してメールを送信する

Last updated at Posted at 2021-02-14

Amazon SES の設定

Terraform を使う

Terraform v0.14.6

resource "aws_ses_domain_identity" "my-ses" {
  domain = aws_route53_record.my-www.name
}

resource "aws_route53_record" "my-route53-record-ses-validation" {
  zone_id = aws_route53_zone.my-route53-zone.id
  name    = "_amazonses.${aws_route53_zone.my-route53-zone.name}"
  type    = "TXT"
  ttl     = "600"
  records = [aws_ses_domain_identity.my-ses.verification_token]
}

resource "aws_ses_domain_dkim" "my-ses-dkim" {
  domain = aws_ses_domain_identity.my-ses.domain
}

resource "aws_route53_record" "my-route53-record-dkim" {
  count   = 3
  zone_id = aws_route53_zone.my-route53-zone.id
  name    = "${element(aws_ses_domain_dkim.my-ses-dkim.dkim_tokens, count.index)}._domainkey.${aws_route53_zone.my-route53-zone.name}"
  type    = "CNAME"
  ttl     = "600"
  records = ["${element(aws_ses_domain_dkim.my-ses-dkim.dkim_tokens, count.index)}.dkim.amazonses.com"]
}

resource "aws_iam_user" "my-smtp-user" {
  name = "ses-smtp-user"
}

resource "aws_iam_user_policy" "my-smtp-user-policy" {
  name = "ses-smtp-user-policy"
  user = aws_iam_user.my-smtp-user.name
  policy = jsonencode({
    Version : "2012-10-17",
    Statement : [
      {
        Effect : "Allow",
        Action : [
          "ses:SendEmail",
          "ses:SendRawEmail"
        ],
        Resource : "*"
      }
    ]
  })
}

resource "aws_iam_access_key" "my-smtp-user-access-key" {
  user = aws_iam_user.my-smtp-user.name
}

output "aws_iam_access_key" {
  value = aws_iam_access_key.my-smtp-user-access-key.id
}

output "aws_iam_secret" {
  value = aws_iam_access_key.my-smtp-user-access-key.secret
}

output "aws_iam_smtp_password_v4" {
  value = aws_iam_access_key.my-smtp-user-access-key.ses_smtp_password_v4
}

※ SESをアジアパシフィック(東京)リージョンで利用する場合は、パスワード著名バージョンv4 を利用します。
 https://qiita.com/charon/items/ab62742d8baf4d275456

※ SESがサンドボックス状態の場合、検証済みメールアドレス に対して送信できます。
 AWSコンソールの Verified identities にメールアドレスを登録して、Verified にします。

スクリーンショット 2021-02-14 12.55.01.png

EC-CUBE4 の設定

.env
- MAILER_URL=null://localhost
+ # MAILER_URL=null://localhost
+ MAILER_URL=smtp://email-smtp.ap-northeast-1.amazonaws.com:587?encryption=tls&auth_mode=login&username=YOUR_NAME&password=YOUR_PASSWORD

username と password には、 Terraform の出力を設定します。

YOUR_NAMEaws_iam_access_key
YOUR_PASSWORDaws_iam_smtp_password_v4

注意1

aws_iam_smtp_password_v4 に、 /+ が含まれている場合があります。
その場合、URLエンコードした文字列を使います。

<?php

echo urlencode('YOUR_PASSWORD');

注意2

今回は、SMTP 経由でメールを送信する方法でした。

AWS SDK を使ってメール送信をする場合は、アクセスキーIDとアクセスキーシークレットを使います。
https://docs.aws.amazon.com/ja_jp/ses/latest/DeveloperGuide/send-an-email-using-sdk.html

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?