Class: MailFactory

Class | MailFactory
In: | lib/mailfactory.rb
Parent: | Object

An easy class for creating a mail message

### Methods

add_attachment add_attachment_as add_header attach attach_as body_to_s buildattachmentboundary buildbodyboundary construct file_encode generate_boundary get_header headers_to_s html= method_missing multipart? new quote_address_if_necessary quote_if_necessary quoted_printable_encode quoted_printable_encode_header quoted_printable_with_instruction rawhtml= remove_header replyto replyto= set_header text= to_s

### Constants

VERSION | = | '1.4.0'

### Public Class methods

new()

### Public Instance methods

add_attachment(filename, type=nil, attachmentheaders = nil)

adds an attachment to the mail. Type may be given as a mime type. If it is left off and the MIME::Types module is available it will be determined automagically. If the optional attachemntheaders is given, then they will be added to the attachment boundary in the email, which can be used to produce Content-ID markers. attachmentheaders can be given as an Array or a String.

add_attachment_as(file, emailfilename, type=nil, attachmentheaders = nil)

adds an attachment to the mail as emailfilename. Type may be given as a mime type. If it is left off and the MIME::Types module is available it will be determined automagically. file may be given as an IO stream (which will be read until the end) or as a filename. If the optional attachemntheaders is given, then they will be added to the attachment boundary in the email, which can be used to produce Content-ID markers. attachmentheaders can be given as an Array of a String.

add_header(header, value)

adds a header to the bottom of the headers

attach(filename, type=nil, attachmentheaders = nil)

Alias for add_attachment

attach_as(file, emailfilename, type=nil, attachmentheaders = nil)

Alias for add_attachment_as

construct(options = Hash.new)

builds an email and returns it as a string. Takes the following options:

`:messageid`: | Adds a message id to the message based on the from header (defaults to false)
`:date`: | Adds a date to the message if one is not present (defaults to true)

generate_boundary()

generates a unique boundary string

get_header(header)

returns the value (or values) of the named header in an array

html=(newhtml)

sets the HTML body of the message. Only the body of the html should be provided

method_missing(methId, *args)

implement method missing to provide helper methods for setting and getting headers. Headers with ’-’ characters may be set/gotten as ‘x_mailer’ or ‘XMailer’ (splitting will occur between capital letters or on ‘_’ chracters)

multipart?()

returns true if the email is multipart

rawhtml=(newhtml)

sets the HTML body of the message. The entire HTML section should be provided

remove_header(header)

removes the named header - case insensitive

replyto()
replyto=(newreplyto)
set_header(header, value)

sets a header (removing any other versions of that header)

text=(newtext)

sets the plain text body of the message

to_s()

returns a formatted email - equivalent to construct(:messageid => true)

### Protected Instance methods

body_to_s()

returns the body as a properly formatted string

buildattachmentboundary(attachment)

builds a boundary string for including attachments in the body, expects an attachment hash as built by add_attachment and add_attachment_as

buildbodyboundary(type, encoding)

builds a boundary string for inclusion in the body of a message

file_encode(str)

returns a base64 encoded version of the contents of str

headers_to_s()

returns the @headers as a properly formatted string

quote_address_if_necessary(address, charset)

Quote the given address if it needs to be. The address may be a regular email address, or it can be a phrase followed by an address in brackets. The phrase is the only part that will be quoted, and only if it needs to be. This allows extended characters to be used in the "to", "from", "cc", and "bcc" headers.

quote_if_necessary(text, charset, instruction = false)

Quote the given text if it contains any "illegal" characters

quoted_printable_encode(text)

rfc2045 compatible. use rfc2047 for headers (such as the Subject line) instead

quoted_printable_encode_header(text)
quoted_printable_with_instruction(text, charset)

Convert the given text into quoted printable format, with an instruction that the text be eventually interpreted in the given charset.

[Validate]