Cerise supports sending mail from applications using Ruby's standard SMTP library which is enhanced to allow encrypted server communication via the STARTTLS command. An arbitrary number of mail servers may be configured for different purposes.
Complex MIME messages with attachments, etc, may be composed using one of the Ruby mail libraries such as TMail or RubyMail.
Mail servers are configured in cerise/cfg/mailserver.cfg. This config file has the following options.
| option | description |
|---|---|
| location | store the corresponding MailConnection in this location |
| host | host the mail transfer agent (MTA) is on |
| port | port the mail transfer agent (MTA) is running on |
| starttls | use TLS and the STARTTLS command to encrypt mail traffic |
| helo_host | claim to be this host when negotiating with the MTA |
| user | authenticate with the MTA as this user |
| pass | password for authentication |
| auth_type | type of SMTP authentication, one of :plain, :login, or :cram_md5 |
The MailConnection class handles sending email. Each
server entry in mailserver.cfg creates one
MailConnection server resource which is stored in the
location specified in the @location configuration option.
| method | description |
|---|---|
| send(from, to, msg) | send a message |
Sending mail is a simple task of looking up a MailConnection which
is stored at the location specified in the @location
config option, and calling send(...).
application.with_mail_connection("mail/Default") { |mc|
from = "cerise@localhost"
to = "cerise@rubyforge.org"
msg = <<EOM
From: "Cerise User" <#{from}>
To: "Cerise" <#{to}>
Subject: Test
This is a test message.
EOM
mc.send(from, to, msg)
}