[Rails] AWS SESのSMTPサーバを使う大まかな流れとSandboxを解除したやりとりの記録

Deviseのパスワード発行メールのように、返信を気にしないメールをサクッと飛ばしたい時がままあるので記事にしました。

# Rails
## gem 
gem 'aws-sdk-rails'
## ActionMailer
```ruby
# config/initializers/aws.rb

Aws::Rails.add_action_mailer_delivery_method(
	:ses,
	credentials: Aws::Credentials.new(ENV.fetch('AWS_ACCESS_KEY_ID') { 'AWS_ACCESS_KEY_ID' },
	                                  ENV.fetch('AWS_SECRET_ACCESS_KEY') { 'AWS_SECRET_ACCESS_KEY' }),
	region: 'ap-northeast-1'
)
```
```ruby
# config/environments/production.rb

config.action_mailer.delivery_method = :ses
```

# AWS
## IAM
ユーザグループにSESのPermission policy を追加する
IAM > [User groups](https://console.aws.amazon.com/iamv2/home?#/groups)

## SES
1. ドメインの所有者確認とDKIM認証してもらう

	[Amazon Simple Email Service](https://ap-northeast-1.console.aws.amazon.com/ses/home?region=ap-northeast-1) 
2. Sandboxの解除リクエスト
3. その後
リクエストの詳細確認の連絡が届いたので、回答したところ無事解除されました🎉（というか日本語でもよかったかも)

Good day, thank you to confirm our request. We respond to enhance information. I wonder if you could look at that. Thanks.

how often you send email:
Less than 5 email a month.

how you maintain your recipient lists:
The administrator can regulate at the web site who will receive mail.

your website or app(please include any necessary links):
Website URL: https://www.example.com

how you manage bounces, complaints, and unsubscribe requests:
Only colleague obtains mail. If the member cannot receive a mail, who can ask the administrator.

It is also helpful to provide examples of the email you plan to send so we can ensure that you are sending high-quality content:

	Subject:
	Reset password instructions

	Body:
	Hello <%= @resource.email %>!

	Someone has requested a link to change your password. You can do this through the link below.

	<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

	If you didn't request this, please ignore this email.
	Your password won't change until you access the link above and create a new one.


> Hello,

> Thank you for submitting your request to increase your sending limits. We are unable to grant your request at this time because we do not have enough information about your use case.

> If you can provide additional information about how you plan to use Amazon SES , we may be able to grant your request. In your response, include as much detail as you can about your email-sending use case and how you intend to use Amazon SES.

> For example, tell us more about how often you send email, how you maintain your recipient lists, your website or app(please include any necessary links), and how you manage bounces, complaints, and unsubscribe requests. It is also helpful to provide examples of the email you plan to send so we can ensure that you are sending high-quality content.

> You can provide this information by replying to this message. Our team provides an initial response to your request within 24 hours. If we're able to do so, we'll grant your request within this 24-hour period. However, if we need to obtain additional information from you, it might take longer to resolve your request.

> Thank you for contacting Amazon Web Services.

> We value your feedback. Please share your experience by rating this correspondence using the AWS Support Center link at the end of this correspondence. Each correspondence can also be rated by selecting the stars in top right corner of each correspondence within the AWS Support Center.

# 参考になりました🙏

https://qiita.com/naokit-dev/items/4668ec379fbe6dcb45cd

https://blog.katsubemakito.net/aws/ses-smtp

https://www.getginger.jp/