Skip to content

Email Sending


namespace Espo\SomeNamespace;

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

class SomeClass
    public function __construct(
        private EmailSender $emailSender,
        private 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