I am using this code to send email using ruby and SMTP protocol
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start('smtp.gmail.com', 'username', 'password', :login)
msgstr = "From: Sender <Sender@gmail.com>
To: Receiver <receiver@gmail.com>
Subject: Spammers List
This is a test message"
smtp.send_message(msgstr, 'sender@gmail.com', 'receiver@gmail.com')
smtp.finish
But the envelope comes together.There is no To and Subject in the received mail.Everything comes in From part itself like this.
Sender To: Receiver Subject: Spammers List
Can anybody say me what is the error in the code?
I believe you have 2 problems. SMTP requires cr-lf linefeeds, and headers can’t have leading spaces. I’m not certain of this point, but I think the last message line might also need to end with a newline. Does it work if you build the content as…