多亏了google-api-client
gem,我才能通过Google API发送电子邮件:
def send_message(from:, to:, subject:, body:)
message = RMail::Message.new
message.header['From'] = from
message.header['To'] = to
message.header['Subject'] = subject
message.body = body
@service.send_user_message(
'me',
upload_source: StringIO.new(message.to_s),
content_type: 'message/rfc822'
)
end
现在我正在尝试将文件附加到电子邮件中,但我找不到如何做到这一点的示例。gem存储库中的example included无法解释这种情况。我已经开始做逆向工程了,但是在尝试了几乎一整天之后,我开始做一些疯狂的事情。
我的最后一次尝试如下:
upload = Google::Apis::Core::UploadIO.new('/path/to/image.png', 'image/png', 'image.png')
file_part = Google::Apis::Core::FilePart.new(nil, upload)
message_object = Google::Apis::GmailV1::Message.new(payload: file_part, raw: 'this is a test body')
service.send_user_message('me', message_object, content_type: 'message/rfc822')
该电子邮件已被退回。
附加文件的正确方式是什么?
https://stackoverflow.com/questions/41488548
复制相似问题