Announcement

Collapse
No announcement yet.

SMTP for rails.

Collapse
X
  • 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

    then

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

    Mail Server Username: web+cooldomain.com
    Incoming Mail Server: mail.cooldomain.com
    Outgoing Mail Server: mail.cooldomain.com (server requires authentication) port 26


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

    Comment


    • #3
      ITS WORKING.

      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
      username+domain.com





      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.




      Hello,

      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:

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

      ************************************************** *******
      Code:
      class Notifier < ActionMailer::Base
      end
      ************************************************** *******


      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.

      Notifier

      Add the following method to your Notifier:

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

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

      Controller

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

      Code:
      def show_page_after_account_creation
      ....
       Notifier.deliver_signup_thanks(user)
      ....
      end

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

      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)
      Code:
      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



      Code:
      helper :application

      to your mailer model


      Configuration

      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:

      Code:
      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 Rails::Initializer.run do |config| block)

      Code:
      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:

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

      Code:
      # Include your app's configuration here:
      ActionMailer::Base.smtp_settings = {
       :address  => "mail.domainname.com",
       :port  => 25,
       :domain  => "domainame.com",
       :user_name  => "[email protected]m",
       :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.

      Comment

      Working...
      X