Explain how to use mailer in Ruby on Rails, railsmailer
Name mails SomethingMailer. Without the Mailer root, you cannot immediately see which is a Mailer and which view is related to it.
Provides HTML and plain text view templates.
An error occurred while sending emails in your development environment. These errors are disabled by default.
# config/environments/development.rb config.action_mailer.raise_delivery_errors = true
In development mode, use smtp.gmail.com to set the SMTP server (unless you have a local SMTP server ).
# Config/environments/development. rb config. action_mailer.smtp_settings = {address: 'smtp .gmail.com ', # more settings}
Provide the default configuration to the host name.
# 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 '} # default_url_options [: host] = 'your _ site.com' in your mailer class'
If you need to use an email link on your website, always use the _ url method instead of the _ path method. The _ url method contains the host name, but the _ path method does not.
# Error You can always find more info about this course = link_to 'where', url_for (course_path (@ course )) # correct You can always find more info about this course = link_to 'where', url_for (course_url (@ course ))
Correctly display the format of the recipient address. Use the following format:
# In Your mailer category default from: 'Your Name <info@your_site.com>'
Set the email sending method in the test environment to test:
# config/environments/test.rb config.action_mailer.delivery_method = :test
The sending method in the development and production environments should be smtp:
# config/environments/development.rb, config/environments/production.rb config.action_mailer.delivery_method = :smtp
When an HTML email is sent, all styles should be intra-row styles, because some users have issues with external styles. To some extent, this makes it more difficult to manage and cause code reuse. There are two similar gems that can convert styles and place them in the corresponding html Tag: premailer-rails3 and roadie.
Avoid sending emails when the page responds. If multiple emails are sent, the page loading delay is caused, and the request may be delayed. Use the help of delayed_job gem to solve the problem of email sending in the background.