All Projects → omnimail → Omnimail

omnimail / Omnimail

Licence: mit
Send email across all platforms using one interface

Projects that are alternatives of or similar to Omnimail

Mailer
A light-weight, modular, message representation and mail delivery framework for Python.
Stars: ✭ 225 (-30.77%)
Mutual labels:  email, sendgrid, mailgun, email-sender
Magento2 Gmail Smtp App
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Stars: ✭ 281 (-13.54%)
Mutual labels:  email, sendgrid, mailgun
Django Anymail
Django email backends and webhooks for Amazon SES, Mailgun, Mailjet, Postmark, SendGrid, Sendinblue, SparkPost and more
Stars: ✭ 1,109 (+241.23%)
Mutual labels:  email, sendgrid, mailgun
Notify
A dead simple Go library for sending notifications to various messaging services.
Stars: ✭ 727 (+123.69%)
Mutual labels:  email, sendgrid, mailgun
Fluentemail
All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.
Stars: ✭ 1,888 (+480.92%)
Mutual labels:  email, sendgrid, mailgun
nest-sendgrid
No description or website provided.
Stars: ✭ 24 (-92.62%)
Mutual labels:  email, sendgrid
wemail
Send Affordable Bulk Email Campaign Through WordPress
Stars: ✭ 19 (-94.15%)
Mutual labels:  mailgun, sendgrid
Email-Spammer
Great script for sending and spaming emails! gmail, yahoo, outlook, hotmail.
Stars: ✭ 79 (-75.69%)
Mutual labels:  email, email-sender
SlmMail
Send mail from Laminas or Mezzio using external mail services.
Stars: ✭ 107 (-67.08%)
Mutual labels:  mailgun, sendgrid
mailer
Simple Email Sending Client for Mailgun & Sendgrid services in crystal
Stars: ✭ 16 (-95.08%)
Mutual labels:  mailgun, sendgrid
content-reminder
⏰ A GitHub Action that reminds you to share your own content
Stars: ✭ 28 (-91.38%)
Mutual labels:  email, sendgrid
release-notify-action
GitHub Action that triggers e-mails with release notes when these are created
Stars: ✭ 64 (-80.31%)
Mutual labels:  email-sender, sendgrid
zaqar
Email microservice writen in Node.js
Stars: ✭ 52 (-84%)
Mutual labels:  email-sender, sendgrid
bulk-email-sender
Send Templatized Dynamic Emails Automatically
Stars: ✭ 30 (-90.77%)
Mutual labels:  email, email-sender
go-mail
📧 A cross platform mail driver for GoLang. Featuring Mailgun, Postal, Postmark, SendGrid, SparkPost & SMTP.
Stars: ✭ 169 (-48%)
Mutual labels:  mailgun, sendgrid
mailcoach-support
Questions and support for Mailcoach
Stars: ✭ 32 (-90.15%)
Mutual labels:  mailgun, sendgrid
ESP-Mail-Client
⚡️Arduino Mail Client Library to send, read and get incoming mail notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.
Stars: ✭ 78 (-76%)
Mutual labels:  email, email-sender
activism-mailbot
No description or website provided.
Stars: ✭ 49 (-84.92%)
Mutual labels:  email, email-sender
Php Imap Client
a easy solution for simple IMAP email access in php
Stars: ✭ 254 (-21.85%)
Mutual labels:  email, email-sender
Grunt Email Workflow
A Grunt workflow for designing and testing responsive HTML email templates with SCSS.
Stars: ✭ 3,010 (+826.15%)
Mutual labels:  email, mailgun

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Join the chat at https://gitter.im/omnimail/omnimail

Send email across all platforms using one interface.

Table Of Content

  1. Requirements
  2. Installation
  3. Providers
  4. Email
  5. Mass Mailings
  6. Factory
  7. Exceptions
  8. Logging
  9. License

Requirements

This library uses PHP 5.6 and greater version.

Installation

It is recommended that you install the Omnimail library through composer. To do so, run the Composer command to install the latest stable version of Omnimail library.

composer require omnimail/omnimail

Providers

AmazonSES

Installation

To use the AmazonSES mailer class, you will need to install the daniel-zahariev/php-aws-ses library using composer.

composer require "daniel-zahariev/php-aws-ses:^0.9.2"

Usage

use Omnimail\Email;
use Omnimail\AmazonSES;

$mailer = new AmazonSES($accessKey, $secretKey, $region, $verifyPeer, $verifyHost, $signatureVersion);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Mailgun

Installation

To use the Mailgun mailer class, you will need to install the mailgun/mailgun-php library using composer. You do also need to install a HTTP client that sends messages. You can use any client that provided the virtual package php-http/client-implementation

composer require mailgun/mailgun-php php-http/guzzle6-adapter

Usage

use Omnimail\Email;
use Omnimail\Mailgun;

$mailer = new Mailgun($apiKey, $domain);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Mailjet

Installation

To use the Mailjet mailer class, you will need to install the mailjet/mailjet-apiv3-php library using composer.

composer require mailjet/mailjet-apiv3-php

Usage

use Omnimail\Email;
use Omnimail\Mailjet;

$mailer = new Mailjet($apikey, $apisecret);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Mandrill

Installation

To use the Mandrill mailer class, you will need to install the mandrill/mandrill library using composer.

composer require mandrill/mandrill

Usage

use Omnimail\Email;
use Omnimail\Mandrill;

$mailer = new Mandrill($apiKey);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Postmark

Installation

To use the Postmark mailer class, you will need to install the wildbit/postmark-php library using composer.

composer require wildbit/postmark-php

Usage

use Omnimail\Email;
use Omnimail\Postmark;

$mailer = new Postmark($serverApiToken);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Sendgrid

Installation

To use the Sendgrid mailer class, you will need to install the sendgrid/sendgrid library using composer.

composer require sendgrid/sendgrid

Usage

use Omnimail\Email;
use Omnimail\Sendgrid;

$mailer = new Sendgrid($apiKey);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

SendinBlue

Installation

To use the SendinBlue mailer class, you will need to install the mailin-api/mailin-api-php library using composer.

composer require mailin-api/mailin-api-php

Usage

use Omnimail\Email;
use Omnimail\SendinBlue;

$mailer = new SendinBlue($accessKey);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

SMTP

Installation

To use the SMTP mailer class, you will need to install the phpmailer/phpmailer library using composer.

composer require phpmailer/phpmailer

Usage

use Omnimail\Email;
use ShahariaAzam\SMTPMailer\SMTPMailer;

$mailer = new SMTPMailer("SMTP HOSTNAME", "SMTP USERNAME", "SMTP PASSWORD");

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Gmail

Installation

To use the Gmail mailer class, you will need to install the phpmailer/phpmailer library using composer.

composer require phpmailer/phpmailer

Usage

use Omnimail\Email;
use Omnimail\Gmail;

$mailer = new Gmail("[email protected]", "password", []);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Email

An Email object implements the EmailInterface inteface. You can create your own Email class and send it to any mailer if it implements the EmailInterface inteface.

To

The To property of the email is for defining the recipients of the email. You can set multiple recipients.

$email = new Email();
$email->addTo('[email protected]', 'Recipient1 Name');
$email->addTo('[email protected]', 'Recipient2 Name');

From

The From property of the email is for defining the mailer of the email.

$email = new Email();
$email->setFrom('[email protected]', 'Sender Name');

CC

Like the To property, the CC property can have multiple recipients.

$email = new Email();
$email->addCc('[email protected]', 'Recipient1 Name');
$email->addCc('[email protected]', 'Recipient2 Name');

BCC

Like the To property, the BCC property can have multiple recipients.

$email = new Email();
$email->addBcc('[email protected]', 'Recipient1 Name');
$email->addBcc('[email protected]', 'Recipient2 Name');

Reply To

The Reply To property of the email is for defining the email that should receive responses.

$email = new Email();
$email->setReplyTo('[email protected]', 'Sender Name');

Subject

The Subject property of the email is for defining the subject of the email.

$email = new Email();
$email->setSubject('Hello, World!');

Text Body

The Text Body property of the email is for defining the text body of the email.

$email = new Email();
$email->setTextBody('This is plain text.');

HTML Body

The HTML Body property of the email is for defining the HTML body of the email.

$email = new Email();
$email->setHtmlBody('<h1>Hi!</h1><p>This is HTML!</p>');

Attachments

The Attachments property of the email is for joining attachments to the email.

Example using string as content

use Omnimail\Email;
use Omnimail\Attachment;

$attachment = new Attachment();
$attachment->setName('my_file.txt');
$attachment->setMimeType('text/plain');
$attachment->setContent('This is plain text');

$email = new Email();
$email->addAttachment($attachment);

Example using file path as content

use Omnimail\Email;
use Omnimail\Attachment;

$attachment = new Attachment();
$attachment->setMimeType('text/plain');
$attachment->setPath(__DIR__ . '/my_file.txt');

$email = new Email();
$email->addAttachment($attachment);

Inline attachments

use Omnimail\Email;
use Omnimail\Attachment;

$attachment = new Attachment();
$attachment->setPath(__DIR__ . '/image.png');
$attachment->setContentId('image.png');

$email = new Email();
$email->setHtmlBody('<p>Hello!</p><img src="cid:image.png">');
$email->addAttachment($attachment);

Factory

Alternatively, you can use the factory method to create a mailer. Consider the following example to create a AmazonSES mailer:

use Omnimail\Omnimail;

$mailer = Omnimail::create(Omnimail::AMAZONSES, ['accessKey' => $accessKey, 'secretKey' => $secretKey]);

Mass Mailings

The mass mailing component is for interacting with mass mailing providers. Currently the code focusses on data retrieval, but in future it should also define creating and sending mass mailings.

There are 2 functions currently described for the Mass mailings interface getMailings and getRecipients.

getMailings

    $mailer = Omnimail::create('Silverpop', array('credentials' => new Credentials(array('username' => $userName...)))->getMailings();
    $mailer->setStartTimeStamp(strtotime('7 days ago'));
    $mailer->setEndTimeStamp(strtotime('now'));
    // Instead of using set methods a Credentials object can be passed in ie.
    // Omnimail::create('Silverpop', array('credentials' => new Credentials(array('username' => $userName...)));
    // The advantage of using the Credentials object is that the object will not disclose
    // the credentials when var_dump or similar is called, helping to make the code
    // more secure.

    $mailings = $mailer->getResponse();
    for ($i = 0; $i < 15; $i++) {
      if (!$mailings->isCompleted()) {
        sleep(15);
      }
      else {
        foreach (\Omnimail\Common\Responses\BaseResponse $mailings as \Omnimail\Common\Responses\Mailing $mailing) {

           $detail => array(
             'subject' => $mailinggetSubject(),
             'external_identifier' => $mailing->getMailingIdentifier(),
             'name' => $mailing->getName(),
             'scheduled_date' => $mailing->getScheduledDate(),
             'start_date' => $mailing->getSendStartDate(),
             'number_sent' => $mailing->getNumberSent(),
             'body_html' => $mailing->getHtmlBody(),
             'body_text' => $mailinggetTextBody(),
             // Note that in the case of Silverpop these statistics are not retrieved by the
             // same api call. This is invisible to the calling function, and unless
             // stats are requested they are not retrieved.
             'number_bounced' => $mailing->getNumberBounces(),
             'number_opened_total' => $mailing->getNumberOpens(),
             'number_opened_unique' => $mailing->getNumberUniqueOpens(),
             'number_unsubscribed' => $mailing->getNumberUnsubscribes(),
             'number_suppressed' => $mailing->getNumberSuppressedByProvider(),
             // 'forwarded'
             'number_blocked' => $mailing->getNumberBlocked(),
             // 'clicked_total' => $stats['NumGrossClick'],
             'number_abuse_complaints' => $mailing->getNumberAbuseReports(),
            );
          }
      }
    }

getMailings

    $mailer = Omnimail::create('Silverpop')->getRecipients();
    $mailer->setUserName($userName);
    $mailer->setPassword($password);
    $mailer->setStartTimeStamp(strtotime('7 days ago'));
    $mailer->setEndTimeStamp(strtotime('now'));
    $mailer->setMailingIdentifier(123);

    $recipients = $mailer->getResponse();
    if (!$recipients->isCompleted()) {
      // sleep or exit & retry later.
    }

    foreach (\Omnimail\Responses\RecipientsResponse $recipients as \Omnimail\Responses\Recipient $$recipient) {

     $detail => array(
       'external_identifier' => $mailing->getMailingIdentifier(),
       'email' =>  $mailing->getEmail(),
       'provider_contact_id' => $mailing->getContactIdentifier(),
       'contact_id' => $mailing->GetContactReference(),
        // Const ACTION_SENT = ‘Sent’, ACTION_OPENED = ‘Open’, ...
       'action' => $mailing->getRecipientAction(),
       'timestamp' => getRecipientActionTimestamp(),
     );

Exceptions

Failures to send emails will throw exceptions.

Exceptions

  • Omnimail\Exception\Exception
  • Omnimail\Exception\EmailDeliveryException
  • Omnimail\Exception\InvalidRequestException
  • Omnimail\Exception\UnauthorizedException
  • Omnimail\Exception\MailerNotFoundException

To catch all exception, consider the following.

try {
    $mailer->send($email);
} catch (\Omnimail\Exception\Exception $e) {
    echo 'Something went wrong: ' . $e->getMessage();
}

To catch specific exceptions, consider the following.

try {
    $mailer->send($email);
} catch (\Omnimail\Exception\UnauthorizedException $e) {
    echo 'Your credentials must be incorrect';
} catch (\Omnimail\Exception\InvalidRequestException $e) {
    echo 'The request is badly formatted, check that all required fields are filled.';
} catch (\Omnimail\Exception\EmailDeliveryException $e) {
    echo 'The email did not go out.';
}

Logging

All mailers constructors take a PSR-3 compatible logger.

Email sent (including the email) are logged at INFO level. Errors (including the email) are reported at the ERROR level.

Example using Monolog

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Omnimail\Mailgun;

$logger = new Logger('name');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::INFO));

$mailer = new Mailgun($apiKey, $domain, $logger);
$mailer->send($email);

License

Omnimail is licensed under The MIT License (MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].