Does Magento 2 have any built-in integration with third party transaction email deliverability systems like Amazon SES, Mandrill, etc., or is the built-in email functionality still based around PHP's mail function? Or are the emails sent with some third thing?

If the answer is mail, are there any third party extensions like SMTPPro for Magento 2 that would let a developer replace the standard email system?

4 Answers 4


I started searching around in the Magento 2 codebase for strings such as 'email', 'message', etc until I found something that sends out an email. I stumbled upon sendPaymentFailedEmail() in vendor/magento/module-checkout/Helper/Data.php. This sets a lot of variables but eventually ties them to a transport object, which is created through a 'transportBuilder'. This transportBuilder is an instance of \Magento\Framework\Mail\Template\TransportBuilder.

In that file, a $transport variable exists, which is an instance of \Magento\Framework\Mail\TransportInterface. Because there is an interface, there is also a regular class called \Magento\Framework\Mail\Transport. When we open the file vendor/magento/framework/Mail/Transport.php, we see that this extends Zend_Mail_Transport_Sendmail;

class Transport extends \Zend_Mail_Transport_Sendmail implements \Magento\Framework\Mail\TransportInterface

This is what you are looking for. Using DI, you'll be able to replace this transport with another email framework instead of Zend_Mail, such as Mandrill or Amazon SES.

Just be sure to include the send() method since that is the method called in sendMessage();

public function sendMessage()
    try {
    } catch (\Exception $e) {
        throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);

Magento 2 TransportBuilder uses a email templates to compose email's body. The simplest way I found to send plain text - use Zend_Mail (that is used by Magento 2 itself):

$email = new \Zend_Mail();
$email->setSubject("Feedback email");
$email->setFrom($from, $nameFrom);
$email->addTo($to, $nameTo);
  • 3
    If you want to send the body in the form of html, you can use $email->setBodyHtml($body) Commented Jul 31, 2017 at 6:44
  • 1
    this is great, however, in case you are using smtp via something like google then follow this thread stackoverflow.com/questions/3455674/…
    – Ahdee
    Commented Sep 24, 2017 at 14:53
  • I have tried this on Magento but getting an error Fatal error: Fatal error: Uncaught Error: Class 'Zend_Mail' not found in /srv/public_html/pub/test.php Commented Dec 2, 2019 at 6:59
  • @NagarajuK , did you include the composer's autloader into your /srv/public_html/pub/test.php?
    – Alex Gusev
    Commented Dec 3, 2019 at 10:41
  • No @AlexGusev can u guide me on how to add composer's autloader in my test.php file? Commented Dec 3, 2019 at 10:52

there is an often made assumption about PHPs mail() beeing outdated and not supporting any 3th. party services.
That is actually wrong, as every good 3th. party service supports an SMTP interface, and so does mail(), too.

Amazon SES does support SMTP.

and sending via SMTP with mail() is described in this answer: https://stackoverflow.com/a/14457410/716029

  • 2
    +1 for useful information -- but I'm still interested in what, if any, abstractions Magento has for supporting the various email via HTTP services. Commented Oct 22, 2015 at 5:12
  • No specific implementations besides Zend_Mail, unfortunately. Commented Jan 25, 2016 at 21:18

Magento 2 Uses \Magento\Framework\Mail\Template\TransportBuilder class for send custom email.

You need to create a simple module and set email_tempaltes.xml file for defining your transaction mail templates.

You can send mail from Adminhtml or Frontend Scope area.

I have shared a link for step by step guide to send a custom mail from Magento 2 using a module.

Send Custom Mail from Magento 2 Module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.