net/smtp
is a very low-level library. It expects the message
to be an email message, including all the headers.
From the documentation
msgstr = <<END_OF_MESSAGE
From: Your Name <your@mail.address>
To: Destination Address <someone@example.com>
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: <unique.message.id.string@example.com>
This is a test message.
END_OF_MESSAGE
require 'net/smtp'
Net::SMTP.start('your.smtp.server', 25) do |smtp|
smtp.send_message msgstr,
'your@mail.address',
'his_address@example.com'
end
In your case, make sure to add a new line between the Headers and the body. Change
<<END_OF_MESSAGE
Subject: test message
. . . rest of the message
END_OF_MESSAGE
to
<<END_OF_MESSAGE
Subject: test message
. . . rest of the message
END_OF_MESSAGE
Instead of using net/smtp
, I highly encourage you to use mail
. mail
uses a more high level interface for sending email messages without loosing the control of the message.
If you don't really care about advanced usage, you can also switch to pony
.