【问题标题】:Ruby Net::SMTP - Send email with bcc: recipientsRuby Net::SMTP - 使用密件抄送发送电子邮件:收件人
【发布时间】:2011-02-01 13:48:52
【问题描述】:

我想使用 Ruby Net::SMTP 发送电子邮件。例行公事

send_message( msgstr, from_addr, *to_addrs )

在我的发送电子邮件的代码中效果很好,但是从这个API 中不清楚如何将电子邮件发送到需要被盲目复制的人员列表(密件抄送:)。

是我遗漏了什么,还是 Net::SMTP 无法实现?

【问题讨论】:

    标签: ruby email bcc


    【解决方案1】:

    是的,使用 Net::STMP 并不容易。但是有一个非常棒的宝石来管理您的电子邮件发送 (http://github.com/mikel/mail)。我鼓励你使用它。

    【讨论】:

    • @shingara - 谢谢。这个看起来很完整。但是,Net::SMTP 甚至有可能吗?我问这个是因为,如果可以哄骗 Net::SMTP 来完成这项工作,我们希望避免使用另一个 Mail gem。
    【解决方案2】:

    send_messageto_addrs 参数指定地址的信封。在to_addrs 中包含地址对包含在邮件标头中的 to 和 cc 地址没有影响。

    要密件抄送收件人,请将地址包含在to_addrs 参数中,但不要将其包含在msgstr 的标头中。例如:

    msgstr = <<EOF
    From: from@example.org
    To: to@example.org
    Cc: cc@example.org
    Subject: Test BCC
    
    This is a test message.
    EOF
    
    Net::SMTP.start(smtp_server, 25) do |smtp|
      smtp.send_message msgstr, 'from@example.org', 
        'to@example.org', 'cc@example.org', 'bcc@example.org'
    end
    

    这将向三个收件人发送电子邮件:to@example.org、cc@example.org 和 bcc@example.org。只有 to@example.org 和 cc@example.org 会在收到的消息中可见。

    【讨论】:

    • @Phil Ross - 谢谢!这正是我所需要的。
    • 注意标题下不能有空格(From:, To: 等)
    猜你喜欢
    • 2011-07-24
    • 2012-03-20
    • 2015-12-19
    • 2016-06-05
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多