gpt4 book ai didi

ruby-on-rails - 如何通过 GMAIL API 发送带有 BCC header 的电子邮件?

转载 作者:数据小太阳 更新时间:2023-10-29 07:59:08 25 4
gpt4 key购买 nike

如何通过 GMAIL API 使用 BCC 发送电子邮件?我向 TO 或 CC 发送电子邮件,但 BCC 不起作用。我使用 Base64.urlsafe_encode64(email.to_s) 并且此代码创建没有密件抄送的字符串。我的工作代码示例:

    email = Mail.new
email.date = Time.now
email.subject = subject
email.to = email_array_to_email_to(to)
email.cc = email_array_to_email_to(cc)
email.bcc = email_array_to_email_to(bcc)
email.reply_to = email_array_to_email_to(reply_to)
email.html_part do
body message
end
request = {
api_method: @google_api.users.messages.to_h['gmail.users.messages.send'],
parameters: { userId: 'me' },
body_object: {
raw: Base64.urlsafe_encode64(email.to_s)
},
}

我是否必须再次调用 GMAIL API 并将此电子邮件与线程 ID 和 BCC 作为收件人一起发送?我用 google-api-client 0.7.1

编辑:邮件对象:

#<Mail::Message:70336725981360,
Multipart: true,
Headers: <Date: Tue,
01 Dec 2015 14:09:08 +0100>,
<Reply-To: >,
<To: ["quatermain32 <my_email@gmail.com>"]>,
<Cc: ["quatermain32 <my_email@gmail.com>"]>,
<Bcc: ["my_email@gmail.com"]>,
<Subject: Test subject>,
<Content-Type: multipart/mixed>>

带有 to_s 的邮件对象:

"Date: Tue, 01 Dec 2015 14:09:08 +0100\r\n
To: my_email <my_email@gmail.com>\r\n
Cc: my_email <my_email@gmail.com>\r\n
Message-ID: <565d9c6e3cf0b_058b7@Olivers-MacBook-Pro.local.mail>\r\n
Subject: Test subject\r\n
Mime-Version: 1.0\r\n
Content-Type: multipart/mixed;\r\n
boundary=\"--==_mimepart_565d9bf468e77_cb0d35e200577a\";\r\n
charset=UTF-8\r\n
Content-Transfer-Encoding: 7bit\r\n
\r\n
\r\n
----==_mimepart_565d9bf468e77_cb0d3ff88645e200577a\r\n
Content-Type: text/html;\r\n
charset=UTF-8\r\n
Content-Transfer-Encoding: 7bit\r\n
\r\n
<p>Test content</p>\r\n
----==_mimepart_565d9bf468e77_cb0d3ff88645e200577a--\r\n
"

最佳答案

您必须手动将密件抄送 header 添加到电子邮件中,它不会发送给收件人。与 gmail-ruby-api 相同 https://github.com/jhk753/gmail-ruby-api/blob/e0d62a751bc31397926c5800532f26e185e00b16/lib/gmail/message.rb

encoded = mail.encoded
if bcc = mail.bcc.join(",").presence
encoded.prepend "Bcc: #{bcc}\n"
end
... send email ...

关于ruby-on-rails - 如何通过 GMAIL API 发送带有 BCC header 的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34002077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com