Forked from hmnhf/mandrillapp_invalid_sender_characters.rb
Last active
September 2, 2015 08:35
-
-
Save aliou/4e84aaf8b22706915767 to your computer and use it in GitHub Desktop.
Mandrillapp invalid sender characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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