Configuring Rails to Send Email

Add the following code to config/environment.rb:

ActionMailer::Base.server_settings = {
  :address        => "mail.yourhostingcompany.com",
  :port           => 25,
  :domain         => "www.yourwebsite.com",
  :authentication => :login,
  :user_name      => "username",
  :password       => "password"
}

Replace each hash value with proper settings for your Simple Mail Transfer Protocol (SMTP) server.

You may also change the default email message format. If you prefer to send email in HTML instead of plain text format, add the following line to config/environment.rb as well:

ActionMailer::Base.default_content_type = "text/html"

Possible values for ActionMailer::Base.default_content_type are "text/plain", "text/html", and "text/enriched". The default value is "text/plain".

ActionMailer::Base.server_settings is a hash object containing configuration parameters to connect to the SMTP server. Here's what each parameter does:


:address - Address of your SMTP server.


:port  - Port number of your SMTP server. The default port number for SMTP is 25.


:domain -   Domain name used to identify your server to the SMTP server. You should use the domain name for the server sending the email to reduce the chance of your email being rejected as spam.


:authentication -  This may be nil, :plain, :login, or :cram_md5. The authentication value you choose here must match the authentication method expected by your SMTP server. If your SMTP server does not require authentication, set this value to nil.


:user_name , :password
Username and password to authenticate to the SMTP server. Required when :authentication is set to :plain, :login, or :cram_md5. If :authentication is set to nil, then these values should be set to nil as well.

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Difference between Validations, Callbacks and Observers