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 7705541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:53:21+00:00 2026-05-31T23:53:21+00:00

I have an ActionMailer class class UserMailer < ActionMailer::Base default from: no-reply@spicy-millennium.com def submission_reminder

  • 0

I have an ActionMailer class

class UserMailer < ActionMailer::Base 
  default from: "no-reply@spicy-millennium.com" 

  def submission_reminder user 
    @user = user           
    mail :to => user.email, :subject => "Your timesheet needs to be submitted!" 
  end    
end

If I call UserMailer.submission_reminder(current_user) in development it returns me a Mail::Message object like expected.

The place in my application where this method is called is in a module I have in the lib folder:

module TimesheetSubmissionNotifier                            
  def self.send_submission_reminders
    User.all.each { |user| UserMailer.submission_reminder(user).deliver }
  end
end

When I call TimesheetSubmissionNotifier.send_submission_reminders in development, UserMailer.submission_remind(user) returns the mail message and deliver is called, everything works as it should.

The problem is when I call TimesheetSubmissionNotifier.send_submission_reminders through an rspec test, UserMailer.submission_reminder(user) returns nil.

If I call UserMailer.submission_reminder(user) directly from an rspec test, it returns the mailer message like expected.

Here are the only lines related to ActionMailer in my config/environment/test.rb:

config.action_mailer.delivery_method = :test 
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

Any ideas why the method is returning nil?

  • 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-31T23:53:22+00:00Added an answer on May 31, 2026 at 11:53 pm

    For those who have a similar problem, I found the issue.

    I was using the should_receive RSpec expectation, which I didn’t realise actually created a mock of the class it is placed on. So I was mocking out the UserMailer class entirely which meant that it was never reaching the actual UserMailer class.

    I couldn’t get it working by using the mock functions, so instead I changed my test to look at the UserMailer.deliveries store and check that the right amount of messages are put in there and that they are being sent to the right email addresses.

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

Sidebar

Related Questions

I have mailer: class AdminMailer < ActionMailer::Base default :from => pejottest@gmail.com def message mail(:to
I have in invitation_mailer.rb the next: class InvitationMailer < ActionMailer::Base default :from => email@email.com
I have a simple ActionMailer class like this: class MyMailer < ActionMailer::Base def mail(from,
I have this code: class Mailer < ActionMailer::Base def foo recipients bar@example.com from foo@example.com
I have two mailers: class Mailer1 < ActionMailer::Base def mail if check_something? end end
I used to have this code for sending mails: class MailTimerMailer < ActionMailer::Base def
I'm having trouble sending mail using SMTP from a Rails app. I have a
in my ActionMailer config file I have this: ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = {
I have a Rails app (2.3.8) where I send emails using ActionMailer from my
I have implemented a custom ActionMapper which obtains the locale from the URI (the

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.