0

我已经通过名为“eblast-bounceback@mydomain.com”的 cpanel 设置了一个转发器,该转发器通过管道连接到跑步者(即,查找有关通过 rails 接收电子邮件的任何教程)。这部分工作得很好 - 我可以告诉脚本正在运行,因为我已将其设置为使用记录器。我遇到的问题是能够在退回电子邮件中找到我的自定义标题“X-Subscriber-Id:”。有没有办法访问原始电子邮件数据,这样我就可以进行正则表达式搜索,还是必须以更复杂的方式进行?

另一方面,如果我收到退回邮件,自动从数据库中删除电子邮件是否明智,或者我需要采取一些额外的步骤来避免恶意意图?

编辑:发布代码...

def receive(email)
    # email.body doesn't work...how do I search for this?  I know it's in the email...
    account = /X\-Subscriber\-Id: (.*)/.match(email.body)[1].split("|") rescue nil
    # If we've found the account info
    logger.info "Nil?: #{account.nil?}"
    if !account.nil?
        id, private_id = account[0].to_i, account[1]
        if @subscriber = Subscriber.find_by_id(id)
            @subscriber.update_attribute(:bouncebacks, @subscriber.bouncebacks.to_i + 1)
            logger.info "Faulty Account: #{@subscriber.email}"
        end
    else
            # This is where we email the admin in case of failure to find an account (manual removal from database)
            # This section is incomplete at this time
        @from = "My Site <admin@mysite.com>"
        @recipients = "admin@mysite.com"
        @subject = "Bounceback could not be processed"
        #@body = email.body -- What do I put here to simply re-send the email?
    end
end
4

1 回答 1

0

使用 email.to_s 而不是 email.body。

于 2014-02-13T01:17:16.920 回答