Rails观点发送消息附件
Rails Viewpoint Send-message attachments
我已将观点 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
选项散列接受 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:
上像这样从我的仓库中导入 gem
gem 'viewpoint', :git => 'https://github.com/durnin/Viewpoint.git'
并再次尝试上面的代码。 (记得在更新 Gemfile 后做 bundle install
)
我已将观点 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
选项散列接受 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:
上像这样从我的仓库中导入 gemgem 'viewpoint', :git => 'https://github.com/durnin/Viewpoint.git'
并再次尝试上面的代码。 (记得在更新 Gemfile 后做 bundle install
)