2

I've been trying to hack together a basic app, and I am to the point where I want to send a welcome message... I thought I had everything in line but it's just not sending. I'm sure that it's just a basic mistake but I'm pulling my hair out here.

app/views/user_mailer/welcome_email.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
  </head>
  <body>
    <h1>Welcome to example.com</h1>
    <p>
      You have successfully signed up to example.com,
      your username is:.<br/>
    </p>
    <p>
      To login to the site, just follow this link:
    </p>
    <p>Thanks for joining and have a great day!</p>
  </body>
</html>

config/environments/production.rb

Scratch::Application.configure do

....
  # Mandrill Connectivity
  config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587, # ports 587 and 2525 are also supported with STARTTLS
    :enable_starttls_auto => true, # detects and uses STARTTLS
    :user_name => "REMOVED",
    :password  => "REMOVED", # SMTP password is any valid API key
    :authentication => 'login', # Mandrill supports 'plain' or 'login'
    :domain => 'yourdomain.com', # your domain to identify your server when connecting
    }
....

app/mailers/user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "info@overflowapp.com"

  def welcome_mail(email)
    mail(:to => email, :subject => "Welcome to Overflow").deliver
  end
end

app/models/user_observer.rb

Class UserObserver < ActiveRecord::Observer
  # We check if it's a new user
  def before_save(user)
    @is_new_record = user.new_record?
    true
   end

  def after_save(user)
  # If it's not a new user we don't want to send them another welcome email
    if @is_new_record then
      UserMailer.welcome_mail(user.email)
    end
  end
end

config/application.rb

....
config.active_record.observers = :user_observer
....
4

1 回答 1

2

It looks like your function in user_mailer.rb is called welcome_mail whereas your template is called welcome_email.html.erb (notice there's no 'e' in the function name). Add on the e, it should send.

You could also try the mailchimp gem which support Mandrill:

https://github.com/mailchimp/mailchimp-gem

于 2013-05-08T22:13:55.653 回答