Question

I'm working on an application with Rails 4 on Ruby 2.0.0. The application sends out an email after a registration in Devise.

This is the code that sends the email:

app/models/sponsor.rb:

after_create :send_email_to_admin

private

def send_email_to_admin
    AdminMailer.new_sponsor_email(self).deliver
end

app/mailers/admin_mailer.rb

class AdminMailer < ActionMailer::Base
  default to: '**removed**'

  def new_sponsor_email(sponsor)
    @sponsor = sponsor
    p @sponsor
    mail(subject: "New Sponsor Registration")
  end
end

And this is the generated email from the log file:

Sent mail to **removed** (725.5ms)
Date: Mon, 02 Sep 2013 15:01:03 -0400
From: **removed**
To: **removed**
Message-ID: <5224e06f4dddd_2e5a3fa0452dcfd874597@centaur.mail>
Subject: New Sponsor Registration
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

A new sponsor has signed up!
==========================

----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
  </head>
  <body>
    <h1>A new sponsor has signed up!</h1>
  </body>
</html>

----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a--

when I try to test the code by creating a sponsor, I just get this error:

Net::SMTPSyntaxError in Devise::RegistrationsController#create
501 5.5.4 Invalid argument

My understanding is that this is typically because the email is and invalid email, but all of my emails are very simple, in the format of name@domain.tld and no-reply@domain.tld.

Was it helpful?

Solution

The issue seemed to be that I was using "domain" in my smtp_settings. When I removed that, I was able to send emails from both Mailgun and Gmail

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top