Detailed _ruby topics on mailer related use in Ruby on Rails

Source: Internet
Author: User
Tags html tags ruby on rails


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.

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.