How to disable ActionMailer in Development?

It’s common practice to just let Rails ignore the mail errors. In your config/environments/development.rb file add, uncomment or modify: # Don’t care if the mailer can’t send config.action_mailer.raise_delivery_errors = false You can also set this: config.action_mailer.perform_deliveries = false See the documentation here http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration You can also set the delivery method to :test, but I have … Read more

Testing ActionMailer multipart emails(text and html version) with RSpec

To supplement, nilmethod’s excellent answer, you can clean up your specs by testing both text and html versions using a shared example group: spec_helper.rb def get_message_part (mail, content_type) mail.body.parts.find { |p| p.content_type.match content_type }.body.raw_source end shared_examples_for “multipart email” do it “generates a multipart message (plain text and html)” do mail.body.parts.length.should eq(2) mail.body.parts.collect(&:content_type).should == [“text/plain; charset=UTF-8”, … Read more

Rails – How to test that ActionMailer sent a specific attachment?

Here’s an example that I copied from my rspec test of a specific attachment, hope that it helps (mail can be creating by calling your mailer method or peeking at the deliveries array after calling .deliver): mail.attachments.should have(1).attachment attachment = mail.attachments[0] attachment.should be_a_kind_of(Mail::Part) attachment.content_type.should be_start_with(‘application/ics;’) attachment.filename.should == ‘event.ics’

How do I create a Mailer Observer

I’m surprised how little there is in Rails’ documentation about this. Basically, ActionMailer in Rails 3 introduces the use of Interceptors (called before the message is sent) and Observers (after the message is sent). To set up an Observer, add the following to an initializer: class MailObserver def self.delivered_email(message) # Do whatever you want with … Read more

Rails ActionMailer with multiple SMTP servers

class UserMailer < ActionMailer::Base def welcome_email(user, company) @user = user @url = user_url(@user) delivery_options = { user_name: company.smtp_user, password: company.smtp_password, address: company.smtp_host } mail(to: @user.email, subject: “Please see the Terms and Conditions attached”, delivery_method_options: delivery_options) end end Rails 4 allows for dynamic delivery options. The above code is straight from the action mailer basics guide, … Read more

Rails Mailer “Net::OpenTimeout: execution expired” Exception on production server only

First, do a direct connection with Telnet: telnet smtp-relay.sendinblue.com 587 Trying 94.143.17.4… This is the basic connection troubleshooting, and works with any provider or port. Replace SendBlue and the 587 port with your actual hostname/port. If you get this error: telnet: Unable to connect to remote host: Connection timed out then, the problem isn’t in … Read more

Render Different View (template) for ActionMailer

You shouldn’t try to do anything after you call mail(). However, to choose another template, you should pass :template_name as an option. For example: template = @user.is_photographer ? “welcome_photographer” : “welcome” mail(:to => “#{@user.name} <#{@user.email}>”, :subject => “Welcome to …”, :template_name => template)

ActionMailer testing with rspec [closed]

How to test ActionMailer with RSpec works for Rails 3 and 4 this information has been taken from a good tutorial Assuming the following Notifier mailer and User model: class Notifier < ActionMailer::Base default from: ‘noreply@company.com’ def instructions(user) @name = user.name @confirmation_url = confirmation_url(user) mail to: user.email, subject: ‘Instructions’ end end class User def send_instructions … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)