我已经整合了 viewpoint gem 以使用 Microsoft Exchange 服务发送电子邮件。我没有发送纯 html 电子邮件的任何问题。我无法发送附有文档的电子邮件。有人请帮助我。
请在下面找到示例
endpoint = "http:///.asmx"
ep_user = ""
ep_password = ""
viewclient = Viewpoint::EWSClient.new ep_user, ep_password
view_client.send_message (:subject => message.subject, :body => message.body, :body_type => "HTML")
-拉吉
我的问题的解决方案更新于 04/27/2016
我以这样一种方式调整了我的代码以使其可行
mail(:from=>"", :to =>"", :subject => "", :doc_path => 'public/images/1.doc')
endpoint = "http:///.asmx"
ep_user = ""
ep_password = ""
viewclient = Viewpoint::EWSClient.new ep_user, ep_password
data_file = message[:doc_path].value
data = [File.open(data_file), "r"]
view_client.send_message (:subject => message.subject, :body => message.body, :body_type => "HTML", :file_attachments => data)
最佳答案
send_message
options hash 接受 file_attachments
在 gem 的 code 中解释的选项.此选项的类型应为 Array<File>
.所以我猜你的代码应该是这样的:
...
array_of_files = [File.join(Rails.root, 'whatever_directory', 'whatever_file.ext')]
view_client.send_message (:subject => message.subject, :body => message.body, :body_type => "HTML", :file_attachments => array_of_files)
更新:
当您尝试发送带有文件的消息时,似乎 gem 坏了(我认为消息只是作为草稿保存而不发送,只有文件)。所以我更新了 gem 来解决这个问题,让我知道它是否正常工作。在你的 Gemfile 上从我的 repo 中导入 gem:
gem 'viewpoint', :git => 'https://github.com/durnin/Viewpoint.git'
然后再次尝试上面的代码。 (记得在更新 Gemfile 后执行 bundle install
)
关于ruby-on-rails - Rails Viewpoint 发送消息附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36873902/