Send Bulk Emails Using Amazon SES

|
| By Webner

Send Bulk Emails Using Amazon SES

Amazon SES- Amazon SES (Simple Email Service) is a cloud based email sending service used by developers and for marketing purposes. It is a reliable, cost-effective service for all sizes of businesses.

Here we will send Email using Amazon SES SDKs to directly integrate Amazon SES into our application.

Simple Steps for Sending the Bulk email without Cc or Bcc are-

Step 1. First we need to create the Amazon SES account by visiting the following URL
https://aws.amazon.com/ses/

Step 2. In the second step we need to generate the Access key for the Amazon SDKs to integrate our project with the AWS.

Send Bulk Emails Using Amazon SES

Step 3. Now we need to download the Amazon SES SDKs library for PHP –

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/getting-started_installation.html

Step 4. Now we need to unzip the downloaded file and place it in our project

and include it by using this code

To use the S3 services we need to include that class
use Aws\Ses\SesClient;

Step 5. Now will create a new Template and Send email to multiple recipients without any Cc or Bcc –

Step 5.1 SesClient::factory is used to create a new Amazon Simple Email Service client using an array of configuration options.

$client = SesClient::factory(array(
				'version'=> 'latest',
				'region' => 'us-east-1',
				'credentials' => array(
						'key' => Configure::read('AWS_KEY'),
						'secret'  => Configure::read('AWS_SECRET'),
				)
		));

Step 5.2 Now we will create a new Template with name ‘SampleEmail’ –

 $client->createTemplate([
 'Template' => [
 'TemplateName' => 'SampleEmail', //unique template name on Amazon SES server
 	 'SubjectPart'  => "Subject of email",
 'HtmlPart'     => "Dear {{name}},

This is an Sample email." ], ]);

Step 5.3 Now we will send Emails in Bulk using the sendBulkTemplatedEmail function of AWS

$client->sendBulkTemplatedEmail([
		'DefaultTemplateData'  => "{ \"name\":\"friend\"}",				
		'Destinations'  => [
				         [
					'Destination'  => [
					'ToAddresses'  => ['firstreceipientmail'],
],
				'ReplacementTemplateData' => "{ \"name\":\"Name1\"}",
						],
[
					'Destination'  => [
					'ToAddresses'  => ['second_receipient_mail'],
					],
			'ReplacementTemplateData' => "{ \"name\":\"Name 2\"}",								],
						[
					'Destination'  => [
					'ToAddresses'  => ['thirdreceipientmail'],
					],
				'ReplacementTemplateData' => "{ \"name\":\"Name3\"}",
						]
				],
		'Source'  => 'sender email',
		'Template'  => 'SampleEmail',
		]);

This was all about how to integrate Amazon SES in our application using PHP and send Emails to multiple recipients in individuals without using Cc or Bcc.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *