Anudeep GI
Anudeep GI

Reputation: 941

How to send mail in Rails 3 from localhost?

I'm new to Rails. How does sending mail in Rails 3 work?

It tried the following, but it doesn't work:

Calling the mailer:

@invited_user = InviteUser.where(:email => @user.email)

Mailer:

class InviteUsersMailer < ActionMailer::Base
  default :from => "[email protected]"

    def invite_biller_email(inviter_details)
      @invitation_details = inviter_details
      @user = User.find(@invitation_details.request_sent_by)
      mail(:to => @invitation_details.email, :subject => "xxxxxxxxxxx")
    end
end

Upvotes: 0

Views: 1744

Answers (2)

ronalchn
ronalchn

Reputation: 12335

Easiest way - use gmail to save having to set up your own mail server. In an initializer file (eg. inside config/initializers/mailer.rb), use the following code to adjust settings:

ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :authentication => :plain,
  :domain => 'yourwebdomain.com',
  :user_name => '[email protected]',
  :password => 'your password',
  :enable_starttls_auto => true
}

After configuring, details on using the ActionMailer is found in the Ruby on Rails Guides.

After you have checked that it works, you can try setting up your own mail server (alternatively, you might have a webhost that runs a mail server for you, in which case re-configure above settings to do that).

Upvotes: 5

Daniel Rikowski
Daniel Rikowski

Reputation: 72534

Have a look at the Rails Guide for sending mails.

In a nutshell there are two things you have to do:

  1. Create a mailer
  2. Configure a delivery method.

These steps and everything else is thoroughly covered in the Rails Guide.

Upvotes: 1

Related Questions