【发布时间】:2021-01-27 19:43:05
【问题描述】:
使用Gmail Service 发送电子邮件,但我对需要传递给Google::Apis::GmailV1::Message 的电子邮件格式有疑问,我正在以以下格式将原始参数传递给它
email_raw = "From: <#{@google_account}>
To: <#{send_to}>
Subject: This is the email subject
The email body text goes here"
# raw is: The entire email message in an RFC 2822 formatted and base64url encoded string.
message_to_send = Google::Apis::GmailV1::Message.new(raw: Base64.encode64(email_raw))
response = @service.send_user_message("me", message_to_send)
即使我在没有 base64 编码的情况下通过 email_raw 也会失败。我提供了有效的电子邮件,但它失败并出现错误
Google::Apis::ClientError(invalidArgument:需要收件人地址)
我检查了Sending an email with ruby gmail api v0.9,还找到了this,但它使用了我在Gmail API Ruby 客户端库中找不到的Mail 类。目前,email_raw 包含 \n 字符,但我已经在没有它的情况下对其进行了测试,但它不起作用。
此外,我还想在邮件中发送附件。
【问题讨论】:
标签: ruby gmail gmail-api google-api-ruby-client