Skip to content

Email Sending

Actual as of v7.0.0.


namespace Espo\SomeNamespace;

use Espo\Core\Mail\EmailSender;
use Espo\Core\Mail\EmailFactory;
use Espo\Core\Mail\SmtpParams; // optional

class SomeClass
    private $emailSender;

    private $emailFactory;

    public function __construct(EmailSender $emailSender, EmailFactory $emailFactory)
        $this->emailSender = $emailSender;
        $this->emailFactory = $emailFactory;

    public function send(): void
        $email = $this->emailFactory->create();

        $email->setBody('Email Body');
        $email->setFromAddress(''); // optional; if not specified, the system address will be used
        $email->setIsPlain(); // Html is by default

        $smtpParams = SmtpParams::create(); // build SMTP params (optionally)

            ->withSmtpParams($smtpParams) // optional
            ->withAttachments([$attachment]) // optional, to send with attachments