问题描述
我需要通过Cloudmailin的POST请求接收传入的电子邮件作为多部分形式的数据。 POST类似于以下内容:
I need to receive incoming emails as multipart-formdata via a POST request from Cloudmailin. The POST resembles the following:
Parameters: {"to"=>"<[email protected]>", "from"=>"whomever@example", "subject"=>"my awesome subject line....
实际上,接收和解析电子邮件非常容易,因为电子邮件只是作为参数发布:params [:to],params [:from]等。但是,如何在rails中模拟此POST请求?
Actually, receiving and parsing emails is super easy because the email is just posted as params: params[:to], params[:from], etc. However, how do I simulate this POST request in rails?
我构建了一个虚拟的Rails应用程序来测试Cloudmailin,所以我有一个实际的请求,但是,它是一个6k字符文件,因此我想加载该文件作为POST请求的参数。我尝试使用内置的rails post和post_via_redirect方法加载文件,但是它转义了所有参数(\ to\),这不好,有什么主意吗?
I built a dummy rails app to test out Cloudmailin, so I have an actual request. However, it's a 6k character file, so I'd like to load this file as the parameters of the POST request. I've tried using the built rails post and post_via_redirect methods to load a file, but it escapes all of the parameters( \"to\"), which is no good. Any ideas?
推荐答案
所以,我最终做了:
@parameters = { "x_to_header"=>"<#{ @detail.info }>",
"to"=>"<#{ @account.slug }@cloudmailin.net>",
"from"=>"#{ @member.email }",
"subject"=>"meeting on Monday",
"plain"=>"here is my message\nand this is a new line\n\n\nand two new lines\n\n\n\nand a third new line"
}
然后只是:
post "/where_ever", @parameters
似乎可以立即完成工作
这篇关于rspec / capybara:如何模拟传入的POST请求? (机架测试不起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!