我已经通过cpanel设置了一个名为'eblast-bounceback@mydomain.com'的转发器,该转发器管道到一个跑步者(即,查找任何通过rails接收电子邮件的教程)。这部分工作得很好——我可以看出脚本正在运行,因为我已经将其设置为使用日志记录器。我遇到的问题是能够在反弹电子邮件中找到我的自定义标题"x订阅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
使用过的电子邮件。