https://github.com/mikel/mail
Ruby
A Really Ruby Mail Library
Mail::Message#initialize
==Making an email
You can make an new mail object via a block, passing a string, file or direct assignment.
===Making an email via a block
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'This is a test email'
body File.read('body.txt')
end
mail.to_s #=> "From: [email protected]\r\nTo: you@...
===Making an email via passing a string
mail = Mail.new("To: [email protected]\r\nSubject: Hello\r\n\r\nHi there!")
mail.body.to_s #=> 'Hi there!'
mail.subject #=> 'Hello'
mail.to #=> '[email protected]'
===Making an email from a file
mail = Mail.read('path/to/file.eml')
mail.body.to_s #=> 'Hi there!'
mail.subject #=> 'Hello'
mail.to #=> '[email protected]'
===Making an email via assignment
You can assign values to a mail object via four approaches:
* Message#field_name=(value)
* Message#field_name(value)
* Message#['field_name']=(value)
* Message#[:field_name]=(value)
Examples:
mail = Mail.new
mail['from'] = '[email protected]'
mail[:to] = '[email protected]'
mail.subject 'This is a test email'
mail.body = 'This is a body'
mail.to_s #=> "From: [email protected]\r\nTo: you@...Edit
git clone [email protected]:mikel/mail.git
cd mail
open lib/mail/message.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Mail--Message-initialize-for-pr
# Commit to gitgit add lib/mail/message.rbgit commit -m "better docs for Mail::Message#initialize"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Mail--Message-initialize-for-pr
hub pull-request
# Celebrate!