No announcement yet.

SMTP for rails.

  • Filter
  • Time
  • Show
Clear All
new posts

  • SMTP for rails.

    How do you set up SMTP mail with ruby on your servers?

    I think I need to direct my mail to your SMTP server, what is its address?

  • #2
    Found the smtp server.

    Still have not got it working, but am a bit closer.

    Found the smtp server address in cpanel.

    cpanel -> email accounts -> email add a new email account -> user: web, password: letmein


    email accounts -> current accounts -> configure mail client -> you'll see

    Mail Server Username:
    Incoming Mail Server:
    Outgoing Mail Server: (server requires authentication) port 26

    Tried adding this to config/environments.rb
    ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.server_settings = {
       :address => "",
       :port => 26,
       :domain => "",
       :authentication => :login,
       :user_name => "",
       :password => "letmein"


    • #3

      1. ActionMailer::Base.server_settings is deprecated and has been replaced with ActionMailer::Base.smtp_settings

      2. The delivery method is :sendmail not :smtp

      ActionMailer::Base.delivery_method = :sendmail

      3. The cpanel displays the wrong email username.

      # Actual username
      [email protected]

      # And not

      Got this really helpful email of one of eukhosts administor's, Alex P. I know it will be useful to a lot of others wanting to send emails with RoR.


      You have to first setup ActionMailer Rails service-layer package for creating email messages.Please refer following steps

      Generate a mailer
      Create a stub file using the generator:

      ************************************************** *******
      ruby script/generate mailer Notifier
      ************************************************** *******
      A file is created in your app/models directory named notifier.rb:

      ************************************************** *******
      class Notifier < ActionMailer::Base
      ************************************************** *******

      A few points to keep in mind

      There are a few confusing things to learn with Action Mailer that took a while to figure out.

      * Action Mailer implementations have views. The above example will reference files in app/views/notifier
      * Each email that you want to send should have one associated method within the class.
      * You don’t call that method. Ever.
      * Instead, you call some dynamic methods, as we’ll see below.

      Let’s assume we’re sending an email to a new user to our website hosting to thank them for signing up, and that user is an object coming from an Active Record that has already been created.


      Add the following method to your Notifier:

      def signup_thanks( user )
       # Email header info MUST be added here
       from  "[email protected]"
       subject “Thank you for registering with our website hosting”
       # Email body substitutions go here
       body :user=> user

      Notice that it is recipients even if you are only sending to one user.


      And the following snippet to the controller in your application that needs to send an email:

      def show_page_after_account_creation

      This threw me for awhile: Make sure you notice the “deliver_” prefix to the method defined in the Notifier model.

      The body of the email comes from a .rhtml file in app/views/notifier – In this example; app/views/notifier/signup_thanks.rhtml:
      (Note: You might have to end the name with _en.rhtml, i.e.signup_thanks_en.rhtml, if you use localization)
      Dear <%= @user.first_name %> <%= @user.last_name %>,
      Thanks for signing up with MyWebsite Hosting!
      Your account will allow you to do blah, blah, blah.
      It is possible to use helpers to your email templates simply by adding

      helper :application

      to your mailer model


      The mail configuration should be set in your environment. See the API documentation for configuration options. To have your configuration available for all server environments put it in /config/environment.rb, otherwise place it in config/environments/production.rb or config/environments/development.rb.

      Make sure ActionMailer is removed from this line in environment.rb:

      config.frameworks -= [ :action_web_service, :action_mailer ]
      The default method for sending mail is SMTP. ActionMailer can also use sendmail, and for initial testing and development you probably want to switch to that. Stick this in your environment.rb: (After the do |config| block)

      ActionMailer::Base.delivery_method = :sendmail
      You may also turn exception raising on and off. The documentation does not state which is the default, so just to be sure, you can turn on exceptions like so:

      ActionMailer::Base.raise_delivery_errors = true
      A sample configuration setting using the default smtp delivery method would look something like this:

      # Include your app's configuration here:
      ActionMailer::Base.smtp_settings = {
       :address  => "",
       :port  => 25,
       :domain  => "",
       :user_name  => "[email protected]",
       :password  => “mypass”,
       :authentication  => :login
      :domain is the name sent to the SMTP server during the handshake. It will be used to form the first “Received:” header, which spam filters usually check.

      Please do not hesitate to contact us if you require any further assistance.
      Best regards,
      Alex P.
      System Administrator.