Saari Development

This blog is intended to be a log of my (Ali Rizvi's) professional ramblings as a software development engineer. I intend to add logs of my experience with different technologies, software, tech books/articles and related stuff from time to time. My intention is to have an archive for my personal use and public benefit.

Tuesday, October 02, 2007

Ruby: net/smtp weirdness - to address can't contain dash/hyphen (-)

This caused me a lot of grief and debugging time.

I am using code like this to send emails from a CGI script:

Net::SMTP.start('smtp.example.com', 25) do |smtp|
smtp.open_message_stream('from@example.com', ['dest-address@example.com']) do |f|
f.puts 'From: from@example.com'
f.puts 'To: dest-address@example.com'
f.puts 'Cc: cc-address@example.com'
f.puts 'Subject: test message'
f.puts
f.puts 'This is a test message.'
end
end


and this is failing silent in my case.

I have discovered through trial and error that if I remove the -(dash) from the to address it works. Dashes in from or CC addresses does not matter.