Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Classes \Postman\Library\Email

joebeeson edited this page Apr 11, 2011 · 4 revisions

The Email object represents all aspects and information (subject, recipients, attachments, etc.) that can be attached to an email and is generally passed off to a Transport (Classes - \Postman\Library\Transport) object for communication to an endpoint.

Methods

__call($method, $arguments)

To expose the internal member variables of the object without writing multiple methods this method will catch and respond to any method calls that appear to ask for a member variable.

For example, if a member variable is _htmlBody the method will look for calls that match getHtmlBody and return the value of the member variable.

setReplyTo($address)

This method sets the Reply-To address for the email. The $address parameter can either be a string or \Postman\Library\Email\Address object.

The returned value will be the \Postman\Library\Email\Address that was used.

setHtmlBody($string = '')

This method sets the content for the HTML body of the email.

The returned value will be the current object.

setTextBody($string = '')

This method sets the content for the text body of the email.

The returned value will be the current object.

setSubject($string = '')

This method sets the content for the subject of the email.

The returned value will be the current object.

setFrom($from)

This method sets the From address for the email. This $from parameter can either be a string or \Postman\Library\Email\Address object.

The returned value will be the \Postman\Library\Email\Address that was used.

addRecipient($recipient, $type = 'to')

This method adds a given $recipient to the object. The $recipient parameter can either be a string, which will be turned into a \Postman\Library\Email\Address\Recipient object, or the intended object itself.

The $type parameter helps to specify what capacity the recipient is to be treated with when sending the email. Accepted values are: to, bcc and cc. This parameter will only be used when passing a string through the $recipient parameter.

The returned value will be the \Postman\Library\Email\Address\Recipient that was used.

addAttachment($file, $name = '')

This method adds an attachment to the email. The $file parameter can either be a path to a local file or a \Postman\Library\Email\Attachment object.

Optionally the $name parameter can be provided to force the visible name of the file. This parameter will only be honored if the $file parameter is a string.

The returned value will be the \Postman\Library\Email\Attachment that was used.

clearRecipients()

This method will clear all recipients attached to the email.

The returned value will be the current object.

clearAttachments()

This method will clear all attachments attached to the email.

The returned value will be the current object.

Notes

The reasoning behind abstracting out all facets of an email to an object is so that Transport objects have a "common ground" or agreement on how to inspect and access those facets.

Because an Email exists independently of any Transport objects, it can be reused, modified and sent many times. If need be one can serialize the object and write it out to persistent storage as well.

Many of the commands that you can perform against an Email object will actually end up returning new objects which help to define their role in the email. You can keep these objects around if you plan to reuse them in later emails; this will help to limit the number of objects you're instantiating.

Related