How can I send mail with rails without a template?

后端 未结 4 1868
旧巷少年郎
旧巷少年郎 2021-02-01 01:29

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 place

4条回答
  •  执笔经年
    2021-02-01 01:47

    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 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.

提交回复
热议问题