Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:08:32+00:00 2026-05-25T22:08:32+00:00

I am trying to send mail using actionmailer on a Rails 3.0.1 application. Here

  • 0

I am trying to send mail using actionmailer on a Rails 3.0.1 application. Here is my setup

config/initializers/setup_mail.rb

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "saidyes.co.uk",
  :user_name            => "username",
  :password             => "password",
  :authentication       => "plain",
  :enable_starttls_auto => true
}

ActionMailer::Base.default_url_options[:host] = "localhost:3000"
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if  Rails.env.development?

config/environments/development.rb

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true

app/mailers/user_mailer.rb

class UserMailer < ActionMailer::Base
  default :from => "info@saidyes.co.uk"

  def self.registration_confirmation(user)
    @user = user
    attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
    mail(:to => "#{user.email}", :subject => "Welcome")
  end
end

app/models/user.rb

require "#{Rails.root}/app/mailers/user_mailer" 

after_create :send_welcome_email

private 
def send_welcome_email
  UserMailer.registration_confirmation(self).deliver
end

The first error i got was an uninitialized constant UserMailer in my Users model class. I fixed it by adding the require at the top of the User model definition. Now I get

undefined local variable or method `attachments’ for UserMailer:Class

I must have configured actionmailer incorrectly or my rails app is not configured correctly to use mailer.

Anyway any advice or help would be appreciated.

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:08:33+00:00Added an answer on May 25, 2026 at 10:08 pm

    I think the simple problem you’ve encountered is that the mail methods should be defined on instances of your mailer class.

    Namely it should be

    class UserMailer < ActionMailer::Base
      def registration_confirmation(user)
        @user = user
        attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
        mail(:to => "#{user.email}", :subject => "Welcome")
      end
    end
    

    Note there is no self

    Take a look at the helpful Rails Guide on the subject

    As in your example you’ll still call the method on the class

    UserMailer.registration_confirmation(user).deliver
    

    The class method does some magic to instantiate an instance, and ensure the correct template is rendered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop application to send mail using configured SMTP client rather
I am trying to create a PHP function to send an e-mail using SMTP
I am trying to send mail using java mail api. My smtp server is
i am trying the below example to send mail using ssl picked from here
I'm trying to send mail from my application server using the following code FILE
I'm trying to send out mail using Google's SMTP in combination with PHPMailer, but
I am trying to use PEAR Mail to send using an external smtp server.
I am trying to send an e-mail using gmail account (Delphi 7, Indy 10)
I am trying to send an email in ASP.NET using system.net.mail the problem is
I am trying to send an HTML email using Perl. open(MAIL,|/usr/sbin/sendmail -t); ## Mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.