Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aliou/4e84aaf8b22706915767 to your computer and use it in GitHub Desktop.
Save aliou/4e84aaf8b22706915767 to your computer and use it in GitHub Desktop.
Mandrillapp invalid sender characters
# I was encountering this exception
# Net::SMTPServerBusy: 401 4.1.7 Bad sender address syntax
# First I searched to see if there's any documentation around this issue,
# didn't find anything, so I wrote this snippet to find those invalid characters
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 25,
:address => "smtp.mandrillapp.com",
:user_name => ENV["MANDRILL_USERNAME"],
:password => ENV["MANDRILL_PASSWORD"]
}
end
def check_if_char_is_invalid c
@invalid_chars ||= []
mail = Mail.deliver do
to ENV["MYEMAIL"]
from "John Doe #{c} <john@doe.com>"
subject 'A transactional email from Mandrill!'
end
rescue Net::SMTPServerBusy
puts "invalid char: #{c}"
@invalid_chars.push(c).uniq!
end
(32..255).each { |x| check_if_char_is_invalid x.chr }
@invalid_chars # => ["\"", "(", ",", ":", ";", "<", ">", "["]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment