接收和处理电子邮件:Heroku,Sendgrid以及可能的Mailman [英] Receiving and Processing Email: Heroku, Sendgrid, and possibly Mailman

查看:141
本文介绍了接收和处理电子邮件:Heroku,Sendgrid以及可能的Mailman的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用为每个用户创建了一个唯一的电子邮件,用户将电子邮件发送到该地址以进行处理。使用Sendgrid,我已将传入电子邮件发送到我的域(托管在Heroku上)到一个地址:

My app creates a unique email for each user, and users send email to that address for processing. Using Sendgrid, I've piped incoming emails to my domain (hosted on Heroku) to an address:

site.com/receive_email

由于电子邮件地址是随机生成的,因此我使用TO字段来确定用户。

I use the TO field to determine the user, since the email address is randomly generated.

我尝试使用外部脚本,例如 Mailman ,但是由于我托管在Heroku上,因此我需要让一名工人全职运行以保持此过程的进行。

I've experimented using an external script like Mailman, but since I'm hosted on Heroku I'd need to have a worker running full time to keep this process going. Not really looking for that at the moment for this test app.

剩下的只是将其作为POST请求处理。我可以在receive_emails上访问POST哈希(参数[ subject]等)。

That leaves processing it as a POST request. I have access to POST hash (params["subject"], etc.) at receive_emails.

这是我遇到的地方

您是否建议处理POST参数中的原始数据,还是可以使用Mailman或ActionMailer之类的东西为我处理电子邮件?

Would you suggest to deal with raw data from the POST params, or can I use something like Mailman or ActionMailer to process the email for me?

推荐答案

我还没有使用Sendgrid将电子邮件转换为发布请求,但是它与heroku插件cloudmailin一起使用时效果很好。这是一个示例,其中有人向您的应用程序发送电子邮件,然后由cloudmailin / sendgrid处理,然后将其转为帖子,然后将其发送到您的控制器,然后该控制器查看消息参数,从电子邮件中查找发件人地址,如果发件人还不存在,则为她创建一个帐户:

I haven't used Sendgrid to turn emails into post requests, but it works fine with cloudmailin, a heroku addon. Here is an example where someone sends an email to your application, it is processed by cloudmailin/sendgrid and turned into a post, and then sends it to your controller, and then the controller looks through the message params, finds the sender from the email address, and if the sender doesn't already exist, creates an account for her:

class CreateUserFromIncomingEmailController < ApplicationController

  require 'mail'

  skip_before_filter :verify_authenticity_token

  parse_message(params[:message])

  def create
    User.find_or_create_by_email(@sender)
  end

private

  def parse_message(message_params)
    @message    = Mail.new(message_params)
    @recipients = @message.to
    @sender     = @message.from.first
  end

end

祝你好运。

这篇关于接收和处理电子邮件:Heroku,Sendgrid以及可能的Mailman的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆