Giter Site home page Giter Site logo

francescogabbrielli / swiftawssestransport Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 64 KB

Swift Mailer Transport for using AWS SES Php Api v3

License: MIT License

PHP 100.00%
aws-ses transport php swiftmailer aws-ses-transport swiftmailer-transport aws bulk-email

swiftawssestransport's Introduction

SwiftAwsSesTransport

What is it?

It's a transport for use with Swiftmailer to send mail over AWS SES. An updated version of the transport by jmhobbs using AWS SesClient v2/v3. Currently still in a development state. Collaborations/ideas welcome.

Where do I put it?

The best way to use it is through composer.

composer require francescogabbrielli/swift-aws-ses-transport

Which will bring in Swiftmailer if you don't already have it installed. Otherwise Swift can autoload it if you put the files in this directory:

[swift library root]/classes/Swift/AwsSesTransport.php

How do I use it?

Like any other Swiftmailer transport:

//Create the desired AWS Transport with the client (for Api v2 do not specify $config_set)
//Standard raw email send
$transport = Swift_AwsSesTransport::newRawInstance($ses_client, $config_set);

//Simple email send (no attachments)
$transport = Swift_AwsSesTransport::newFormattedInstance($ses_client, $config_set);

//Template email send
$transport = Swift_AwsSesTransport::newTemplatedInstance($ses_client, $config_set, $template);
    ->setReplacementData(TEMPLATE_DATA);
    
//Bulk template email send 
$transport = Swift_AwsSesTransport::newBulkInstance($ses_client, $config_set, $template)
    ->setReplacementData(TEMPLATE_DATA)
    ->addDestination(...)
    ->addDestination(...)
    ...
    ->addDestination(...);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
...
$mailer->send($message);

Symfony1.X configuration

```yaml
# app/frontend/config/factories.yml

all:
  mailer:
    class: sfMailer
    param:
      transport:
        class:          SwiftAwsSesTransport
```

How do I get the message ID on send?

You may register a Swift_Events_ResponseListener plugin with a callback.
See example/responseListener.php for details. It is especially useful in combination with async calls.

$transport
    ->setAsync(true)
    ->registerPlugin(
        new Swift_Events_ResponseReceivedListener() {
            public function responseReceived( \Swift_Events_ResponseEvent $evt ) {
                $response = $evt->getResponse();//Aws\Result
                $sent = $evt->getSource()->getCount();
                echo sprintf( "Message-ID %s.\n", $response->get("MessageId"));
            }
        });

For sync calls, the message ID is available in the header of the message:

$message->getHeaders()->get("X-SES-Message-ID");

For bulk send, there is an utility method to read all the sent message IDs:

$transport->getSentMessageIds();

Swiftmailer Version

Tested on versions 5 and 6. For version 5 change method signature inside AwsSesTransport:

public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) 

to

public function send(Swift_Mime_Message $message, &$failedRecipients = null) 

Acknowledgments

swiftawssestransport's People

Contributors

francescogabbrielli avatar

Stargazers

 avatar

Watchers

 avatar

swiftawssestransport's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.