Class: SystemMail::Message
- Inherits:
-
Object
- Object
- SystemMail::Message
- Defined in:
- lib/system_mail/message.rb
Overview
Manages compiling an email message from various attributes and files.
Constant Summary collapse
- BASE64_SIZE =
76- UTF8_SIZE =
998- SETTINGS =
{ :sendmail => '/usr/sbin/sendmail -t', :base64 => 'base64', :file => 'file --mime-type --mime-encoding -b', :storage => ENV['TMP'] || '/tmp', }.freeze
Instance Method Summary collapse
-
#deliver ⇒ Object
Delivers the message using sendmail.
-
#initialize(options = {}) ⇒ Message
constructor
Creates new message.
- #settings ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Creates new message. Available options:
-
:text, String, Textual part of the message
-
:enriched, String, Enriched alternative of the message (RFC 1896)
-
:html, String, HTML alternative of the message
-
:from, String, ‘From:’ header for the message
-
:to, String or Array of Strings, ‘To:’ header, if Arrey, it gets joined by ‘, ’
-
:subject, String, Subject of the message, it gets encoded automatically
-
:files, File or String of file path or Array of them, Attachments of the message
Options :text, :enriched and :html are interchangeable. Option :to is required.
Examples:
mail = Message.new(
:from => '[email protected]',
:to => '[email protected]',
:subject => 'test subject',
:text => 'big small normal',
:html => File.read('test.html'),
:attachments => [File.open('Gemfile'), 'attachment.zip'],
)
44 45 46 47 48 49 50 51 52 |
# File 'lib/system_mail/message.rb', line 44 def initialize(={}) @body = {} @to = [] @mutex = Mutex.new %W(text enriched html from to subject attachments).each do |option| name = option.to_sym send(name, [name]) end end |
Instance Method Details
#deliver ⇒ Object
Delivers the message using sendmail.
Example:
mail.deliver #=> nil
61 62 63 64 65 66 67 68 |
# File 'lib/system_mail/message.rb', line 61 def deliver validate with_storage do write_headers end end |
#settings ⇒ Object
70 71 72 |
# File 'lib/system_mail/message.rb', line 70 def settings @settings ||= SETTINGS.dup end |