Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Mailer: sending emails to a local file

Is there any way to send emails in rails 3 to a local file or so, instead of using an SMTP server? I'd like to test the email's contents without using any kind of SMTP, ideally only in DEV environment.

The best would be a local SMTP or something that allowed me to inspect emails, check email addresses, etc.

like image 719
Miguel Ping Avatar asked Sep 21 '10 19:09

Miguel Ping


People also ask

How do I use SMTP in Ruby on Rails?

Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.

What is ActionMailer?

Action Mailer allows you to send emails from your application using mailer classes and views.

What is Default_url_options?

The default_url_options setting is useful for constructing link URLs in email templates. Usually, the :host , i.e. the fully qualified name of the web server, is needed to be set up with this config option. It has nothing to do with sending emails, it only configures displaying links in the emails.


1 Answers

You can use the :test system delivery

ActionMailer::Base.delivery_method = :test

There are also a :file delivery_method

ActionMailer::Base.delivery_method = :file

You can define where put all email with file_settings

ActionMailer::Base.file_settings = { :location => Rails.root.join('tmp/mail') }
like image 180
shingara Avatar answered Oct 03 '22 23:10

shingara