Explain how to use mailer in Ruby on Rails, railsmailer

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.