Class EmailService

Class EmailService

Represents the public API for the Email service of the system. External users must use this class for all the email operations except.

Important: Since the attachments will be flat-stored in the "uploads/attachmetns" directory the "send" and "queue" method will have to perform multiple writes to the database in order to get robust attachment handling that will not crash the rest of the service.

EmailService implements EmailServiceInterface
Package: Email
Category: System
Located at Services/System/Email/EmailService.inc.php

Methods summary

public __construct( EmailRepositoryInterface $repository, EmailFactoryInterface $factory, MailerAdapterInterface $mailerAdapter, AttachmentsHandlerInterface $attachmentsHandler )

Class Constructor

public create( EmailContactInterface $sender, EmailContactInterface $recipient, EmailSubjectInterface $subject, EmailContentInterface $content = null ) : EmailInterface

Creates a new email

public send( EmailInterface $email )

Sends and saves an email.

public queue( EmailInterface $email )

Saves an email as pending (will not be sent).

public write( EmailInterface $email )

Writes an email instance to the DB.

public getById( IdType $id ) : EmailInterface

Returns an email by id.

public findById( IdType $id ) : EmailInterface|null

Finds an email by ID.

public delete( EmailInterface $email )

Removes an email from the database.

public filter( string $p_keyword, array $limit = array(), array $order = array() ) : EmailCollection

Filters email records with provided keyword string.

public validateEmailAddress( string $p_emailAddress ) : boolean

Validate a string email address.

public sendPending( void )

Sends pending email records.

public getPending( void ) : EmailCollectionInterface

Return pending email records as an email collection.

public getSent( void ) : EmailCollectionInterface

Returns sent email records as an email collection.

public getAll( void ) : EmailCollection

Returns all email records from the database.

public sendCollection( EmailCollectionInterface $collection )

Sends a collection of emails.

public queueCollection( EmailCollectionInterface $collection )

Queues a collection of emails.

public writeCollection( EmailCollectionInterface $collection )

Writes a collection of emails into database.

public deleteCollection( EmailCollectionInterface $collection )

Deletes a collection of emails.

public getRecordCount( string $p_filterKeyword = '' ) : integer

Returns the current count of the email records in the database.

public deleteEmailsByCustomerEmail( CustomerEmail $email )

Removes all emails from the data base that have the given email address as sender or recipient.

public getEmailsByCustomerEmail( CustomerEmail $email ) : EmailCollection

Gets all emails from the data base that have the given email address as sender or recipient.

Properties summary

protected $repository : EmailRepositoryInterface

E-Mail repository.


		
protected $mailerAdapter : MailerAdapterInterface

Mailer adapter.


		
protected $factory : EmailFactoryInterface

E-Mail factory.


		
protected $attachmentsHandler : AttachmentsHandlerInterface

E-Mail attachments handler.