如何发送没有模板的导轨邮件? [英] How can I send mail with rails without a template?
问题描述
在我的Rails 3项目中,我想发送一些简单的通知电子邮件。我不需要为他们做一个模板或做任何逻辑。我只是想从系统的各个地方把它们从他们那里消灭。
In my Rails 3 project, I want to send some simple notification emails. I don't need to make a template for them or do any logic. I just want to fire them off from various places in the system.
如果我在一个任意的ruby脚本中这样做,我会使用 pony 。但是,我仍然希望使用rails邮件设施和配置,以便我获得与系统其余邮件相同的可靠性和设置。
If I were doing this in an arbitrary ruby script I would use pony. However, I'd like to still use the rails mail facilities and configuration, so that I get the same reliability and setup that I have for the rest of the mail in my system.
最简单的方法是什么?理想情况下,将会有一些方法,如
What's the most simple way to do this? Ideally there would be some method like
ActionMailer.send(:to => 'foo@example.com', :subject =>"the subject", :body =>"this is the body")
推荐答案
在没有模板的rails 3中发送邮件的最简单的方法是调用 c $ c>基础
直接跟着交付
方法,
The simplest way to send mail in rails 3 without a template is to call the mail
method of ActionMailer::Base
directly followed by the deliver
method,
对于例如,以下将发送纯文本电子邮件:
For ex, the following would send a plain text e-mail:
ActionMailer::Base.mail(from: "me@example.com", to: "you@example.com", subject: "test", body: "test").deliver
http://api.rubyonrails.org/classes/ActionMailer/ Base.html#method-i-mail 为您提供了所有的标题选项以及关于如何直接发送带有text / plain和text / html部件的多部分/替代电子邮件的想法。
http://api.rubyonrails.org/classes/ActionMailer/Base.html#method-i-mail gives you all the header options and also ideas about the how to send a multipart/alternative email with text/plain and text/html parts directly.
这篇关于如何发送没有模板的导轨邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!