ãAWSã®ãµã¼ãã¹ç¾¤ã®ä¸ã§ãå°å³ã ãã©æé£ããµã¼ãã¹ã®ä¸ã¤ã«Amazon Simple Email Serviceï¼SESï¼ãããã¾ããä»ã®ãµã¼ãã¹ã«è² ããã«ãã©ãã©ã便å©ãªæ©è½ã追å ããã¦ãã£ã¦ãã¾ãããã®ä¸ã®ä¸ã¤ã2012å¹´10æã«è¿½å ãããã¡ã¼ã«éä¿¡ãã¹ãç¨æ©è½ã§ãããã®åããAmazon SES Mailbox Simulatorãããã¯ä½ãã¨ããã¨ãããªããæå®ã®çµæãè¿ãã¦ãããã¡ã¼ã«ã¢ãã¬ã¹ã§ãã
ã使ãéã¨ãã¦ï¼ã¤èãããã¾ããã¾ãã¯ãAmazonèªèº«ãèªã£ã¦ããããã«ãä¸æ£éä¿¡ã®ãã¹ãçã§ãã¹ãå®æ½è
ã®ã¢ã«ã¦ã³ãã®è©ä¾¡ï¼ã¬ãã¥ãã¼ã·ã§ã³ï¼ãä¸ããªãçºã§ãã次ã«ãã¡ã¼ã«éä¿¡äºæ
ã®èªåãã¹ãï¼ã¦ããããã¹ãï¼ããããããããå¹æãããã¾ããä¸è¬çã«ã·ã¹ãã å¤ã¸ã®ãã¹ãã¯ãå°é£ãä¼´ãã¾ããç¹ã«ã¡ã¼ã«çã®å ´åãç¸æå
ããã£ã¦ã®ãµã¼ãã¹ã§ãããããæå¾
ããçµæãè¿ãã¦ãããã¢ãã¬ã¹ãããã°ãé常ã«æé£ãã§ãã
ãå®å
ã®ç¨®é¡ã¨ãã¦ã¯ã以ä¸ã®ï¼ã¤ãããã¾ãã
ç¨®é¡ | å®å | åè |
---|---|---|
æ£å¸¸ã¡ã¼ã« | [email protected] | æ£å¸¸ã«é ä¿¡ããããã®ã¨ãã¦æ±ããã |
Unknown User | [email protected] | SMTP 550 ("Unknown User")ã®ã¬ã¹ãã³ã¹ã³ã¼ãã§æå¦ããã |
ä¸å¨ã¡ãã»ã¼ã¸(OOTO) | [email protected] | Mailbox Simulatorã¯Amazon SESã«ä¸å¨ã¡ãã»ã¼ã¸(OOTO)ãè¿ä¿¡ããã |
ã¹ãã æ±ã | [email protected] | âã¹ãã âã ã¨è¨å®ããISPãAmazon SESã«ã¯ã¬ã¼ã å¿çãéä¿¡ããã¨ãã£ãã±ã¼ã¹ãã·ãã¥ã¬ã¼ããã |
éä¿¡ããã㯠| [email protected] | Amazon SESãéä¿¡ããããã¯ãã"Address Blacklisted" ã¨ã©ã¼ã¡ãã»ã¼ã¸ãå«ãã MessageRejectedã¨ã©ã¼ãè¿ã |
ãããã§ã¯ãå°ã試ãã¦ã¿ã¾ãããã以åãRubyでSESを使うコードãæ¸ããã®ã§ãã»ã¼ãã®ã¾ã¾ã§ãã¹ãã
# -*- encoding: utf-8 -*- require 'rubygems' require 'aws-sdk' require 'nkf' ses = AWS::SimpleEmailService.new( :access_key_id => ENV['AWS_ACCESS_ID'], :secret_access_key => ENV['AWS_SECRET_KEY']) #ISO-2022-jp body_text = NKF.nkf('-jw','æ¬æTest') subject = NKF.nkf('-Mw', 'ã¿ã¤ãã«Test') res = ses.send_email( :subject => subject, :to => '[email protected]', :from => '[email protected]', :body_text => body_text, :body_text_charset => 'ISO-2022-JP' ) p res
ããã®çµæã¯ãç¡æ ã«ãnilãããã¨æã£ã¦ドキュメントãè¦ã¦ã¿ã¾ããã
Instance Method Summary (collapse)
- (EmailAddressCollection) email_addresses
Returns a collection that represents all of the verified email addresses for your account.
- (IdentityCollection) identities
- (Hash) quotas
Returns a hash of SES quotas and limits.
- (nil) send_email(options = {})
Sends an email.
- (nil) send_raw_email(raw_message, options = {}) (also: #deliver, #deliver!)
Sends a raw email (email message, with header and content specified).
- (Array of Hashes) statistics
Returns an array of email statistics.
nilãè¿ãã£ã½ãã§ãã
ãä¸å¿ãã½ã¼ã¹ãè¦ã¦ã¿ã¾ããã
def send_email options = {} require_each(options, :subject, :from) require_one_of(options, :to, :cc, :bcc) require_one_of(options, :body_text, :body_html) # these three options can be passed strings or arrays of strings, # but the service requires them in a list (array) [:to, :cc, :bcc, :reply_to].each do |key| if options[key] options[key] = [options[key]].flatten end end accepted_options = { :subject => %w(message subject data), :subject_charset => %w(message subject charset), :to => %w(destination to_addresses), :cc => %w(destination cc_addresses), :bcc => %w(destination bcc_addresses), :from => %w(source), :from => %w(source), :reply_to => %w(reply_to_addresses), :return_path => %w(return_path), :body_text => %w(message body text data), :body_text_charset => %w(message body text charset), :body_html => %w(message body html data), :body_html_charset => %w(message body html charset), } client.send_email(nest_options(options, accepted_options)) nil end
nilãè¿ãã£ã½ãã§ãã
ä»æ¹ããªãã®ã§ãJavaçã試ãã¦ã¿ã¾ãããJavaã®ä½¿ãæ¹ã¯å¿å´ã®å½¼æ¹ãªã®ã§ãGlacierの時に設定したモノãåèã«
import java.io.IOException; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient; import com.amazonaws.services.simpleemail.model.Body; import com.amazonaws.services.simpleemail.model.Content; import com.amazonaws.services.simpleemail.model.Destination; import com.amazonaws.services.simpleemail.model.Message; import com.amazonaws.services.simpleemail.model.SendEmailRequest; import com.amazonaws.services.simpleemail.model.SendEmailResult; public class Ses { public static void main(String[] args) throws IOException { AWSCredentials credentials = new PropertiesCredentials( Sample.class.getResourceAsStream("AwsCredentials.properties")); AmazonSimpleEmailService sesClient = new AmazonSimpleEmailServiceClient(credentials); SendEmailRequest sendRequest = new SendEmailRequest(); String toAddress = "[email protected]"; String fromAddress ="[email protected]"; sendRequest.setDestination(new Destination().withToAddresses(toAddress)); Message message = new Message(); Content subject = new Content().withData("Subject Test"); message.setSubject(subject); Content text = new Content().withData("Body Test"); Body body = new Body().withText(text); message.setBody(body); sendRequest.setMessage(message); sendRequest.setSource(fromAddress); SendEmailResult result = new SendEmailResult(); result = sesClient.sendEmail(sendRequest); System.out.println(result.getMessageId()); } }
ãããããJavaçã¯SendEmailResultã¯ã©ã¹ã¯ãããã®ã®ãã¡ãã»ã¼ã¸IDããä¿æãã¦ããã¾ãããä½ãæ ¹æ¬çã«åéããã¦ãã模æ§ã§ãã使ç¨ä¾ãã°ã°ã£ã¦ã¿ãã¨ãsuz-labさんが使い方の解説ããã¦ããã¦ãã¾ãããã©ãããSNSã«éç¥ãã¦ããã模æ§ã§ãã
ãèãã¦ã¿ãã°å½ããåã§ãããã¡ã¼ã«ã®éä¿¡ã¯éåæã®å¦çãªã®ã«ãå³åº§ã«å¿çã³ã¼ããè¿ã£ã¦ããã¨æå¾
ããã®ãééãã§ãããï¼ã¨ããããä½ãæã£ã¦è¿ãå¤ã«å
¥ã£ã¦ããã¨æã£ãã®ããã¡ãã£ã¨åã®èªåãåãè©°ããããï¼
ãã¨è¨ãäºã§æ°ãåãç´ãã¦ã管çã³ã³ã½ã¼ã«ã®SESã®Verified Sendersã®æãããã¹ãã«ä½¿ãã¢ãã¬ã¹ã«è¨å®ãè¡ãã¾ããã¡ã¼ã«ã¢ãã¬ã¹ãé¸ãã§ãFeedback Detailsã§Edit Configurationãè¡ãã¾ããSNS Configurationã§ä»»æã®SNSã®ãããã¯ãæå®ãã¾ãã
[:large]
ãããã¦ããã¹ãéä¿¡ãç¡äºã«ã¡ãã»ã¼ã¸ãæ¥ã¾ããã
{"notificationType":"Bounce","bounce":{"reportingMTA":"dns; a194-13.smtp-out.amazonses.com","bounceType":"Permanent","bouncedRecipients":[{"emailAddress":"[email protected]","status":"5.0.0","diagnosticCode":"smtp; 5.1.0 - Unknown address error 550-'5.1.1 user unknown' (delivery attempts: 0)","action":"failed"}],"bounceSubType":"General","timestamp":"2012-12-16T08:28:30.000Z","feedbackId":"0000013ba2d42884-92eefaa4-475a-11e2-bb75-6b3d4723cd04-000000"},"mail":{"timestamp":"2012-12-16T08:28:30.000Z","source":"[email protected]","messageId":"0000013ba2d42676-c36edf1f-645c-4b8a-9b70-948ba98291e4-000000","destination":["[email protected]"]}}
ãèªåãã¹ãã«ä½¿ããã¨æã£ãã®ã§ãã¨ãã§ããªãæ¹åéãããã¦ãã¾ãããã使ãæ¹ã¯ä¸å¿è§£ãã¾ãããä¸æ¹ã§SNS対å¿ã¨ãããã¨ã§ãããã°ã©ããã«ãªæ¤è¨¼ãå¯è½ãªã®ã§æé£ãã§ãããããå°ãæ¢ã£ã¦ã¿ã¾ããLet's try!
See Also:
RubyからAmazon SESでメールを送る
Amazon Glacierのサンプルソース アップロード編
AWSで大量メール配信するなら、Amazon SESで決まり
åç
§ï¼
suz-lab - blog: "Amazon SES Mailbox Simulator"を試してみた
【AWS発表】Mailbox Simulator - Amazon Simple Email Serviceにメール送信テスト用機能が追加! - Amazon Web Services ブログ
【AWS発表】Simple Email Service (SES) にプログラム可能なフィードバック通知機能が追加 - Amazon Web Services ブログ
【AWS発表】 Amazon Simple Email Service (SES)がSMTPをサポート - Amazon Web Services ブログ
【AWS発表】Amazon Simple Email Service (SES)でドメイン一括検証が可能に