Net::SMTPSyntaxError: 501 Invalid characters detected

So, you’re using ActionMailer and you get an icredibly funky error when trying to send mails - something like this:

Net::SMTPSyntaxError: 501 Invalid characters detected

Round about now is when you start thinking about that career in advertising you passed up when you look at your environment.rb file, which contains something like this:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = { 
:address => "mail.fbi.com",
:port => 666, 
:user_name => "mailman@fbi.com", 
:password => "billclinton", 
:authentication => :cram_md5
}
ActionMailer::Base.perform_deliveries = true

Nothing unusual or special. In fact, it looks like every other damn email configuration you’ve set up to date. But here’s the catch: In the ‘HELO’ phase of the connection with the mail server, the domain name of your machine is sent to the mail server - and this is where the magic dissapeared.

To fix, simply add the domain setting with an appropriate value to your smpt_settings, so that it looks something like this:

ActionMailer::Base.smtp_settings = {
:address => "mail.fbi.com",
:port => 666,
:user_name => "mailman@fbi.com",
:password => "billclinton",
:domain => "localhost.com",
:authentication => :cram_md5
}

Short URL for this post: http://tmblr.co/ZM2Vby5KsDY