I have this code:
require "net/smtp"
MAIL_SERVER = "xxx.ad.xxx.net"
def lib_sending_report(email_hash)
# define message body
message = <<"MESSAGE_END"
From: <#{email_hash[:sender]}>
To: <#{email_hash[:recipients]}>
MIME-Version: 1.0
Content-type: text/html
Subject: #{email_hash[:subject]}
<p>Hi All,</p>
<p>We've just executed a round of load test.</p>
<p>Regards</p>
MESSAGE_END
Net::SMTP.start(MAIL_SERVER) do |smtp|
smtp.send_message message, email_hash[:sender], email_hash[:recipients]
end
end
test = ""
lib_sending_report( {:sender => "abc@xxx.com",
:recipients => "abc@xxxx.com",
:subject => "Load.Test.Report.of.#{test}"} )
When I change :recipients => "abc@xxxx.com" to :recipients => "abc@xxxx.com;efg@xxx.com", it gives me this error:
501 5.5.4 Invalid Address (Net::SMTPSyntaxError)
I can successfully send email when :recipients => "abc@xxxx.com" just have one recipient.
Where am I wrong? It seems that the separator(semicolon) I used is wrong.
I tried to use comma instead of semicolon, but it didn’t work
Net::SMTP’s
send_messagetakes an array of “To:” address strings.Per the documentation:
This example from the documentation shows how:
Net::SMTP.start('smtp.example.com') do |smtp| smtp.send_message msgstr, 'from@example.com', ['dest@example.com', 'dest2@example.com'] end