Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails one liner email sending?

How can I send an email in one line without creating a mailer class?

I need to set all the params including :from (which is different than the smtp user)

So far I got this:

# ok not exactly a one liner, but it doesn't matter
ActionMailer::Base.mail(:from => '[email protected]', :to => '[email protected]', :subject => 'subject bla') do
  'content bla'
end.deliver

The content is not working, I receive a blank email

like image 889
HappyDeveloper Avatar asked Mar 02 '12 15:03

HappyDeveloper


People also ask

What is action mailer?

1 Introduction. Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.


1 Answers

ActionMailer::Base.mail(from: '[email protected]', to: '[email protected]', subject: "Welcome to My Awesome Site", body: 'I am the email body.').deliver

Omg, we have one-liner!

like image 121
jibiel Avatar answered Sep 30 '22 13:09

jibiel