简体   繁体   English

我的ruby应用程序如何接收和解析带有附件的电子邮件?

[英]How can my ruby app receive and parse emails with attachments?

I'd like to allow users to send an attachment via email to my app and have the attachment saved in their account. 我想允许用户通过电子邮件将附件发送到我的应用,并将附件保存在他们的帐户中。 Each user would have a unique and private email to send files to. 每个用户都有一个唯一的私人电子邮件来发送文件。 Something similar to Send to Dropbox is what I'm going for. 我想要的是类似于发送到Dropbox的东西。

I've been searching for a while now and can't find anything on how to approach this. 我已经搜索了一段时间,但找不到有关如何解决此问题的任何信息。 I'm guessing I'm searching the wrong thing. 我猜我在搜索错误的内容。 My ultimate question/s is/are: what are the components that go into a feature like this and what are the best gems to get the job done? 我的最终问题是:像这样的功能中包含哪些组件?完成这项工作的最佳方法是什么?

Thanks. 谢谢。

Use procmail or .forward to pipe the incoming mail into your script. 使用procmail或.forward将传入的邮件传递到脚本中。 The script comes in along STDIN in mbox format (same as http: headers-blankline-body). 该脚本以mbox格式随STDIN一起提供(与http:headers-blankline-body相同)。 I have no clue if there are gems, you can parse it manually with zero difficulty. 我不知道是否有宝石,您可以手动将其解析为零难度。

.forward is way easier than procmail: on a system with sendmail, if you have an account named my_app , put in ~my_app/.forward the following line: .forward比procmail更容易:在具有sendmail的系统上,如果您有一个名为my_app的帐户,请在~my_app/.forward输入以下行:

|/foo/bar/my_app/process_mail.rb

and it will pipe any mails coming to my_app@example.com into /foo/bar/my_app/process_mail.rb . 它将把发送到my_app@example.com所有邮件发送到/foo/bar/my_app/process_mail.rb Separate into headers and body, split headers into lines, find the From and Subject header, identify your user, do what you want with the rest. 分为标题和正文,将标题拆分为行,找到FromSubject标题,标识您的用户,其余部分做您想做的事情。

On Rails, I suspect you should do: 在Rails上,我怀疑您应该这样做:

|/usr/bin/env rails runner /foo/bar/my_app/process_mail.rb

or if using Bundler, 或者如果使用Bundler,

|/usr/bin/env bundle exec rails runner /foo/bar/my_app/process_mail.rb

so you get your Rails environment for your script. 这样您就可以获得脚本的Rails环境。

Below is a detailed explanation on how to intercept emails with rails: 以下是有关如何使用Rails拦截电子邮件的详细说明:

http://steve.dynedge.co.uk/2010/09/07/incoming-email-in-rails-3-choosing-the-right-approach/ http://steve.dynedge.co.uk/2010/09/07/incoming-email-in-rails-3-choosing-the-right-approach/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Rails应用程序上的ruby接收电子邮件 - how to receive emails from a ruby on rails app Google为什么拒绝我的Ruby on Rails应用中的电子邮件? - Why is google rejecting emails from my Ruby on Rails app? 使用Ruby on Rails通过SendGrid发送带有附件的电子邮件 - Sending emails with attachments using Ruby on Rails via SendGrid 如何配置我的服务器以从Ruby on Rails发送电子邮件 - How configure my server to send emails from Ruby on Rails 我可以将我的应用程序降级到旧版本的Ruby和Rails吗? 怎么样? - Can I downgrade my app to older versions of Ruby and Rails? How? 如何永久解锁 Google 帐户验证码以在我的 heroku 应用程序中发送电子邮件? - How can I unlock Google account captcha permanently to send emails in my heroku app? 如何配置我的应用程序以仅允许特定电子邮件注册 devise? - How can I configure my app to allow only specific emails to register with devise? Rails 3从Apple Mail.app阅读带有附件的电子邮件 - Rails 3 reading emails with attachments from Apple Mail.app Ruby Action Mailer:我如何发送每日电子邮件? - Ruby Action Mailer: How can I send daily emails? 如何在Ruby on Rails应用程序中接受(解析)www-url编码的数据? - How can I accept (and parse) www-url-encoded data in a Ruby on Rails app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM