Added framework support for processing incoming emails with an Action Mailer class.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@941 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 425aa50a
*SVN*
* Added framework support for processing incoming emails with an Action Mailer class.
*0.7.1* (7th March, 2005)
* Bind to newest Action Pack (1.5.1)
......
......@@ -5,6 +5,12 @@ are used to consolidate code for sending out forgotten passwords, welcoming
wishes on signup, invoices for billing, and any other use case that requires
a written notification to either a person or another system.
Additionally, an Action Mailer class can be used to process incoming email,
such as allowing a weblog to accept new posts from an email (which could even
have been sent from a phone).
== Sending emails
The framework works by setting up all the email details, except the body,
in methods on the service layer. Subject, recipients, sender, and timestamp
are all set up this way. An example of such a method:
......@@ -47,6 +53,36 @@ ApplicationMailer, it would look like this:
ApplicationMailer.deliver_signed_up("david@loudthinking.com") # sends the email
ApplicationMailer.new.signed_up("david@loudthinking.com") # won't work!
== Receiving emails
To receive emails, you need to implement a public instance method called receive that takes a
tmail object as its single parameter. The Action Mailer framework has a corresponding class method,
which is also called receive, that accepts a raw, unprocessed email as a string, which it then turns
into the tmail object and calls the receive instance method.
Example:
class Mailman < ActionMailer::Base
def receive(email)
page = Page.find_by_address(email.to.first)
page.emails.create(
:subject => email.unquoted_subject, :body => email.unquoted_body_with_all_parts
)
if email.has_attachments?
for attachment in email.attachments
page.attachments.create({
:file => attachment, :description => email.unquoted_subject
})
end
end
end
end
This Mailman can be the target for Postfix. In Rails, you would use the runner like this:
./script/runner 'Mailman.receive(STDIN.read)'
== Dependencies
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册