Name the mails the Somethingmailer. Without Mailer, it is not immediately apparent which is a Mailer, and which view is related to it.
Provides HTML and plain text view templates.
Enable mail failure to send error in your development environment. These errors are disabled by default.
# config/environments/development.rb
config.action_mailer.raise_delivery_errors = True
Use smtp.gmail.com to set up SMTP servers in development mode (unless, of course, you have your own local SMTP server).
# config/environments/development.rb
config.action_mailer.smtp_settings = {address
: ' smtp.gmail.com ',
# More Settings
}
Provides the default configuration to host names.
# config/environments/development.rb
config.action_mailer.default_url_options = {host: "#{local_ip}:3000"}
# config/environments/production.rb
config.action_mailer.default_url_options = {host: ' Your_site.com '}
# in your mailer class
default_url_options[:host] = ' your_site.com '
If you need to use an email link on your site, always use the _url method instead of the _path method. The _url method contains the host name, and the _path method does not.
# error
can always find more info about this course
= link_to ' here ', Url_for (Course_path (@course))
# correct
you can always find more info about this course
= link_to ' here ', Url_for (Course_url (@course))
Correctly displays the format of the send and recipient addresses. Use the following format:
# in your mailer category
default from: ' Your Name <info@your_site.com> '
Determine the email Send method for test environment set to test:
# config/environments/test.rb
Config.action_mailer.delivery_method =: Test
The method of sending the development and production environment should be SMTP:
# config/environments/development.rb, config/environments/production.rb
Config.action_mailer.delivery_method =: SMTP
When you send HTML emails, all styles should be inline styles, because some users have problems with external styles. In a way this makes it more difficult to manage and cause code reuse. There are two similar gems that can convert styles and put them in corresponding HTML tags: PREMAILER-RAILS3 and roadie.
You should avoid sending emails when the page responds. If multiple emails are sent, the page loading delay is caused and the request may be exceeded. Use the help of Delayed_job gems to overcome the problem of sending emails in background processing.