PITS Blog
  • Home
  • Services
    • Dedicated team Have your own development team at our location in Kerala, India. We tailor our employees individually to your project.
    • Website & web shop Get into the online business and sell your products around the clock. Or convince yourself with a modern website on desktop and mobile devices.
    • Application development We develop very individual web or software applications for you for a wide variety of needs.
    • Hybrid or native iOS & Android Apps Online business is often done on the go today, and the trend is rising. Invest now and make your software mobile-compatible.
  • Credentials
  • Technology
  • Process
  • About us
  • Contact
  • White papers
  • Jobs
  • Blog
  • Startups
�
Avatar

Send bulk templated email using Amazon SES API

By Renjith R Nair on February, 8 2018
demo post

By Visakh R N

WordPress and .NET

By Priyanka K

Roadmap to become a DevOps Engineer

By Francis Varghese

Gutenberg - More Than Just An Editor

By Priyanka K

In most cases, while sending bulk email newsletters the email template will be the same. These templates will contain custom tokens which should be replaced accordingly for every destination address. Using Amazon SES sendBulkTemplatedEmail API we can pass tokens and replace text as arguments, then Amazon will do the replace and sending procedure. Quick steps for sending bulk templated email using Amazon SES API is explained below.

Import Amazon aws-sdk-php library to project
use composer to install library to your project

composer require aws/aws-sdk-php

then use these classes,

use Aws\Credentials\Credentials;
use Aws\Ses\SesClient;

Start client instance
Start an Amazon SES client instance using your amazon credentials and set region accordingly. Available regions are email.us-east-1.amazonaws.com, email.us-west-2.amazonaws.com, email.eu-west-1.amazonaws.com

$client = new SesClient([
                            'credentials' => new Credentials(USERNAME, PASSWORD),
                            'region'      => REGION,
                            'version'     => 'latest',
                            ]);

Create template
CreateTemplate API operation can be used to create email templates. These templates include a subject line, and the text and HTML parts of the email body. The subject and body sections may also contain unique values that are personalized for each recipient

$client->createTemplate([
                'Template' => [
				  'TemplateName' => 'MyTemplate', //unique template name
				  'SubjectPart'  => "Hello, {{name}}!",
				  'TextPart'     => "Hello {{name}},
                                                      Accessory for your {{favcar}}.",
                                  'HtmlPart'     => "Hello {{name}},
                                                      \r\nAccessory for your {{favcar}}.",
                                ],
                ]);

Send templated email to different destinations
After creating an email template, you can use it to send email. The SendBulkTemplatedEmail operation is useful for sending unique emails to multiple destinations in a single call to the Amazon SES API.

$client->sendBulkTemplatedEmail([
   'DefaultTemplateData' => '',//JSON dencoded, key as token and value as replacement text.
                                    Common data for any destination
   'Destinations'        => [
        [
           'Destination'    => [
              'BccAddresses' => ['', ...],
              'CcAddresses'  => ['', ...],
              'ToAddresses'  => ['', ...],
            ],
           'ReplacementTemplateData' => '',//template data for current destination
        ],
        // ...
   ],
   'ReplyToAddresses'  => ['', ...],
   'ReturnPath'        => '',
   'Source'            => '',
   'Template'          => '',
]);

Note: Utilize available Amazon SES Exception handlers for error management. Use asynchronous methods to get promise objects, createTemplateAsync for template creation & sendBulkTemplatedEmailAsync to send bulk email.

We'd love to hear from you.

Contact us

Switzerland
thomas(at)pitsolutions(dot)com
+41 (0) 43 558 4360

India
enquiries(at)pitsolutions(dot)com
+91 (0) 471 270 0615 / 715

UAE
mohammed(at)pitsolutions(dot)com
+971 (0) 4 359 8610

USA
arnab(at)pitsolutions(dot)com
+1 (0) 703 945 8076

Copyright © 2019PIT Solutions AG.An ISO 9001:2015 certified company. All Rights Reserved

SCROLL TO TOP