I've set up a forwarder through cpanel called 'eblast-bounceback@mydomain.com' which pipes to a runner (i.e., look up any tutorial on receiving emails through rails). This part works just fine - I can tell that the script is running because I've set it to use the logger. The problem I'm having is being able to find my custom header "X-Subscriber-Id: " within the bounceback email. Is there a way to access the raw email data so I can just do a regex search or do I have to do this in a more complicated way?
On another note, is it wise to au开发者_开发知识库tomatically remove the email from the database if I get a bounceback or is there some sort of addition steps I need to take to avoid malicious intent?
EDIT: Posted Code...
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
Used email.to_s instead of email.body.
精彩评论