0

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
2

2 Answers 2

5

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).

1
  • to add, if you want to limit this to an environment such as development-- you can drop this into a specific environment by using the above hash within config.action_mailer.smtp_settings = {}
    – skilleo
    Commented Sep 22, 2014 at 21:01
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.