Skip to content

Instantly share code, notes, and snippets.

@hmnhf
Last active November 13, 2020 09:20
Show Gist options
  • Save hmnhf/da95ecd81240bbe96836 to your computer and use it in GitHub Desktop.
Save hmnhf/da95ecd81240bbe96836 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 but 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
(32..255).each_with_object([]) do |codepoint, invalid_chrs|
chr = codepoint.chr
begin
Mail.deliver do
to ENV["MYEMAIL"]
from "John Doe #{chr} <john@doe.com>"
subject 'A transactional email from Mandrill!'
end
rescue Net::SMTPServerBusy
invalid_chrs.push(chr)
end
end
# => ["\"", "(", ",", ":", ";", "<", ">", "["]
@goofansu
Copy link

goofansu commented Aug 3, 2020

Thank you for the gist, saving a lot of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment