我正在开发一个 Outlook 插件,它应该为我们的用例将电子邮件同步到另一台服务器。 我能够将邮件存储在远程数据库上,但问题在于获取附件。 由于加载项本身不能发送附件,我必须向远程服务器发送一些详细信息,例如(ews url、访问令牌、附件 ID 等),以便它可以使用该信息与 Outlook 服务 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我需要将Outlook EWS电子邮件及其附件转发到Rails服务器。
我随Viewpoint gem获得的附件以Viewpoint::EWS::Types::FileAttachment
对象的形式返回。
如何使用rest-client
库将这些附件传递到Rails服务器?
我设法通过使用StringIO
并给它一个:path
来上传文件
# email is a Viewpoint::EWS::Types::Message
# email_endpoint is a RestClient::Resource
attachments = email.attachments.map do |attachment|
file = StringIO.new(Base64.decode64(attachment.content))
file.class.class_eval { attr_accessor :original_filename, :content_type, :path }
file.original_filename = attachment.file_name
file.content_type = attachment.content_type
file
end
response = email_endpoint.post(
email: {
subject: email.subject,
attachments: attachments
}
)
rest-client
库将自动处理响应:path
和:read
作为文件的对象,并使用分段上传。
然后,每个附件在Rails中显示为具有正确文件名的ActionDispatch::Http::UploadedFile
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.