我有这段代码:
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}"} )
当我将:recipients => "abc@xxxx.com"
更改为:recipients => "abc@xxxx.com;efg@xxx.com"
时,它会给我这个错误:
501 5.5.4 Invalid Address (Net::SMTPSyntaxError)
当:recipients => "abc@xxxx.com"
只有一位收件人时,我可以成功发送电子邮件。
我哪里错了?似乎我使用的分隔符(分号)是错误的。
我尝试使用逗号而不是分号,但它不起作用
答案 0 :(得分:6)
Net :: SMTP&#39; s send_message
采用&#34; To:&#34;地址字符串。
根据文件:
to_addr是字符串或字符串或字符串数组,表示目标邮件地址。
文档中的这个示例显示了如何:
Net::SMTP.start('smtp.example.com') do |smtp| smtp.send_message msgstr, 'from@example.com', ['dest@example.com', 'dest2@example.com'] end