{"id":40999,"date":"2016-09-30T16:59:19","date_gmt":"2016-09-30T11:29:19","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=40999"},"modified":"2024-01-02T17:44:32","modified_gmt":"2024-01-02T12:14:32","slug":"aws-ses-integration-for-java-applications","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/aws-ses-integration-for-java-applications\/","title":{"rendered":"AWS SES Integration for Java Applications"},"content":{"rendered":"<p><strong>Use Case<\/strong><\/p>\n<p>I came across a use-case, where I had to integrate <strong>Amazon Simple Email Service (SES)<\/strong> to send <strong>transactional emails<\/strong> from <a title=\"Java consulting services\" href=\"http:\/\/www.tothenew.com\/java-development-services\">a JAVA application<\/a> using my own registered domain. This blog will guide the reader through the basic steps required for setting up or integrating Amazon SES with my JAVA application.<\/p>\n<p><strong>About Amazon SES<\/strong><\/p>\n<p>It is an email service built and maintained by <strong>Amazon<\/strong>. It has <strong>cost efficient<\/strong>,<strong> reliable and scalable infrastructure<\/strong> ready to serve its customers. It can be used to send transactional email, marketing messages, or any other type of high-quality content to the customers. It can also be used to receive messages and deliver them to an Amazon S3 bucket, call your custom code via an <a href=\"http:\/\/www.tothenew.com\/blog\/introduction-to-aws-lambda\/\">AWS Lambda<\/a> function, or publish notifications to Amazon SNS.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/01\/amazon-ses.png\" alt=\"Image result for aws ses\" \/><\/p>\n<p><strong>Requirements<\/strong><\/p>\n<p><strong>1.<\/strong>\u00a0<strong>AWS Account<\/strong> with full access to <strong>Simple Email Service<\/strong> <strong>(SES)<\/strong>.<br \/>\n<strong>2.<\/strong> <strong>Registered domain<\/strong> to be used for sending email.<br \/>\n<strong>3.<\/strong> Working <strong>Java application<\/strong> for sending emails.<\/p>\n<p><strong>Setting Up Amazon Simple Email Service (SES)<\/strong><\/p>\n<p>To start the setup we first need to have a domain from which we can send emails. Following sample domain was created:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41076\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-2-rt53.png\" alt=\"SES-2-rt53\" width=\"420\" height=\"307\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-2-rt53.png 420w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-2-rt53-300x219.png 300w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/p>\n<p>Now, we have a sample domain, <strong>sample.videoready.tv.\u00a0<\/strong>Now we need to verify it so that we can setup Amazon Simple Email Service (SES) for this domain.<\/p>\n<p><strong>Following are the steps to setup SES<\/strong><\/p>\n<p><strong>1.<\/strong> <strong>Go to SES console<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41078\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-1.png\" alt=\"SES-1\" width=\"681\" height=\"483\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-1.png 681w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-1-300x212.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-1-624x442.png 624w\" sizes=\"(max-width: 681px) 100vw, 681px\" \/><\/p>\n<p><strong>2.<\/strong>\u00a0On the left we have an option for <strong>Domain<\/strong>, click on the\u00a0domain option and then select <strong>Verify a New Domain:<\/strong><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41080\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-3.png\" alt=\"SES-3\" width=\"759\" height=\"382\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-3.png 759w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-3-300x150.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-3-624x314.png 624w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/>\u00a0<\/strong><\/p>\n<p><strong>3.<\/strong> Enter the name of created domain and select the box to <strong>Generate DKIM Settings.\u00a0<\/strong>The domain is not verified util the records generated in this process are entered in DNS, in my case it is <strong>AWS Route 53<\/strong>. Following records will be generated:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41081\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-4.png\" alt=\"SES 4\" width=\"1019\" height=\"652\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-4.png 1019w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-4-300x191.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-4-624x399.png 624w\" sizes=\"(max-width: 1019px) 100vw, 1019px\" \/><\/p>\n<p>It gives an option to setup all records in <strong>AWS Route53<\/strong>. But I do not need to set the <strong>MX records<\/strong>, but in my use-case, I only needed to send emails and not receive any on my domain. So we setup only<strong> TXT<\/strong> and <strong>DKIM<\/strong> records in <strong>AWS Route53<\/strong>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41082\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-12.png\" alt=\"SES 12\" width=\"936\" height=\"410\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-12.png 936w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-12-300x131.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-12-624x273.png 624w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41083\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-14.png\" alt=\"SES 14\" width=\"894\" height=\"529\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-14.png 894w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-14-300x177.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-14-624x369.png 624w\" sizes=\"(max-width: 894px) 100vw, 894px\" \/><\/p>\n<p>After these records have been setup. The domain takes some time to be verified:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41084\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-domain-vrf.png\" alt=\"SES-domain-vrf\" width=\"941\" height=\"191\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-domain-vrf.png 941w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-domain-vrf-300x60.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-domain-vrf-624x126.png 624w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/p>\n<p>4. After the domain verification, we can send a test email from the SES console, to verify that it is functioning properly:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41102\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES_test-email.png\" alt=\"SES_test-email\" width=\"636\" height=\"339\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES_test-email.png 636w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES_test-email-300x159.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES_test-email-624x332.png 624w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/p>\n<p>Now that we have verified that the Amazon SES service is functioning properly. We move on to integrating this with the <strong>Java application<\/strong>. To integrate it with a java application we use <strong>SMTP setting\u00a0<\/strong>and then with <strong>AWS JAVA SDK<\/strong>. The SMTP settings generate <strong>SMTP credentials<\/strong>, which are setup in the application code. These credentials allow the application to use Amazon SES and use the verified domain to send mails.<\/p>\n<p><strong>Setting Amazon SES for SMTP<\/strong><\/p>\n<p>On the left, we have an option <strong>SMTP Setting<\/strong>, click on it. Then select <strong>Generate My SMTP Credentials:<\/strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41104\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp.png\" alt=\"SES smtp\" width=\"876\" height=\"336\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp.png 876w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp-300x115.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp-624x239.png 624w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/p>\n<p>Following credentials are generated, which need to be configured in the Java Application. So that application is authorized to use SES for sending emails:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41105\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp-creds.png\" alt=\"SES smtp creds\" width=\"455\" height=\"193\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp-creds.png 455w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-smtp-creds-300x127.png 300w\" sizes=\"(max-width: 455px) 100vw, 455px\" \/><\/p>\n<p>In the Java Application, we define <strong>SMTP_USERNAME <\/strong>and<strong> SMTP_PASSWORD<\/strong>, which authorizes the access to Amazon SES. Apart from SMTP credentials we set the sender and the receiver of the mail. Here, we also define the content and subject of the mail:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41192\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/ses-smtp1.png\" alt=\"ses-smtp1\" width=\"1500\" height=\"700\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/ses-smtp1.png 1500w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/ses-smtp1-300x140.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/ses-smtp1-1024x477.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/ses-smtp1-624x291.png 624w\" sizes=\"(max-width: 1500px) 100vw, 1500px\" \/><\/p>\n<p><strong>Setting Amazon SES with AWS JAVA SDK<\/strong><\/p>\n<p>If using <strong>AWS JAVA SDK<\/strong> to send emails, we can use AWS user <strong>secret key <\/strong>and<strong> access<\/strong> <strong>key<\/strong> to authorize Java application to send emails using <strong>Amazon SES. <\/strong>After installing the SDK we setup the keys as follows, to allow the access of application on Amazon SES:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41168\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK.png\" alt=\"SES-SDK\" width=\"1034\" height=\"402\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK.png 1034w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-300x116.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-1024x398.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-624x242.png 624w\" sizes=\"(max-width: 1034px) 100vw, 1034px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-41169\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-CREDS.png\" alt=\"SES SDK CREDS\" width=\"976\" height=\"279\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-CREDS.png 976w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-CREDS-300x85.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/SES-SDK-CREDS-624x178.png 624w\" sizes=\"(max-width: 976px) 100vw, 976px\" \/><\/p>\n<p>Now, the Java application&#8217;s integration with Amazon SES is complete, and emails can be sent using both <strong>SMTP<\/strong> as well as <strong>AWS JAVA SDK<\/strong> method. Using Amazon SES is good in such use-case because\u00a0if the application becomes heavy and it needs to send a\u00a0large number of emails.\u00a0The large volume can easily be handled by Amazon SES due to its scalable architecture.<\/p>\n<p>Hope this blog was of help to you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use Case I came across a use-case, where I had to integrate Amazon Simple Email Service (SES) to send transactional emails from a JAVA application using my own registered domain. This blog will guide the reader through the basic steps required for setting up or integrating Amazon SES with my JAVA application. About Amazon SES [&hellip;]<\/p>\n","protected":false},"author":916,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":34},"categories":[1174,2348,446,1],"tags":[4076,248,2366,3233,1892,596,4844],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40999"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/916"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=40999"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40999\/revisions"}],"predecessor-version":[{"id":59826,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40999\/revisions\/59826"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=40999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=40999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=40999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}