Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 1004 Bytes

email-sending.md

File metadata and controls

38 lines (30 loc) · 1004 Bytes

Email Sending

Example:

<?php
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->setSubject('Subject');
        $email->setBody('Email Body');
        $email->addToAddress('[email protected]');
        $email->setFromAddress('[email protected]'); // optional; if not specified, the system address will be used
        $email->setIsPlain(); // Html is by default
        
        $smtpParams = SmtpParams::create(); // build SMTP params (optionally)

        $this->emailSender
            ->withSmtpParams($smtpParams) // optional
            ->withAttachments([$attachment]) // optional, to send with attachments
            ->send($email);
    }
}