Ruby on Rails email sending Environment Settings

Source: Internet
Author: User
Tags ruby on rails gmail password
Running environment:
Ruby 1.8.6
Rails 1.2.5
Gem 1.0.1

The gmail server is used here. Because actionMailer in rails does not support TLS (SSL) connections, it is the only transmission method on the Gmail SMTP server. There is a plug-in provided for this problem on the Internet. The following describes the specific configuration steps:
1. Install the plug-in: Open cmd and enter the directory of the rails project.
Input ruby script/plugin install http://svn.xlsuite.org/trunk/vendor/plugins/action_mailer_tls/

Find "smtp_tls.rb" in the project directory and put it in the lib directory of the project.

2. Configure the environment of the rails project:
Open the config/environment. rb file of the project:

Add: require 'smtp _ tls '# reference libsmtp_tls.rb
ActionMailer: Base. delivery_method =: smtp # Use smtp to send emails

ActionMailer: Base. default_charset = "UTF-8" # specifies the character set used to send the mail

ActionMailer: Base. server_settings = {
: Address => "smtp.gmail.com", # The email server used.
: Port => 587, # the port number of the email server
: Domain => "xxx.com", # Temporarily ignore
: Authentication =>: Login, # not very clear, write as follows
: User_name => "yourname@gmail.com", # Use the mail server account (here is Google, so it is the Goole mailbox account)
: Password => "yourpassword", # Use the password of the email server
# Note: I only specified the email server here. It does not mean that if I specified the Google email server, I had to use Google's email to send emails, or use another email address to send emails through Google's email server.
}


3. Restart the Project server

If your rails version is newer:
Add the following configuration information between the environment. rb file Rails: Initializer. run do | config | and end:
# Config/environments/development. rb
Config. action_mailer.raise_delivery_errors = true # An error is thrown to the application.

# Set delivery method to: smtp,: sendmail or: test
Config. action_mailer.delivery_method =: smtp # mail sending Method

# These options are only needed if you choose SMTP delivery
Config. action_mailer.smtp_settings = {
: Address => 'smtp .gmail.com ',
: Port => 587,
: Authentication =>: Plain,
: User_name => 'yourname @ gmail.com ', # your Gmail account
: Password => 'yourpassword' # your Gmail Password
}

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.