views:

52

answers:

1

I am running a cron job that checks for new email on a Gmail account every minute. If any new mail is found, it triggers a receive function that begins as follows:

  def receive(email)     
    # REPORT SOME INFORMATION ABOUT INBOUND EMAIL RECEIPT
    puts "SUBJECT: #{email.subject}" 
    puts "#{email.class}"
    puts email.to.inspect
    puts email.bcc.inspect
    puts email.from.inspect
    ...
  end

I would like to process only email that addresses the system in the TO or BCC fields. The idea is that users should not disclose the various destination email addresses to others.

The problem is that this function cannot seem to pull BCC information from the TMail object that is passed as the "email" parameter to this object. TO addresses come through fine, but not BCCs.

Anyone know why this might be the case?

+1  A: 

TL;DR version: As an email client, you cannot reliably retrieve the BCC field.

Of course it's missing the BCC field. Once used to direct an email it's removed from the message.

BCC means Blind Carbon Copy. And is used to copy people on messages without giving their addresses out to every one else receiving the message. If the incoming email still had this information it wouldn't serve it's purpose.

You should probably read the section RFC 2822 about addressing.

What you're asking about isn't explicitly defined and becoming implementation dependent. The Mail User Agent (Outlook/Thunderbird/Gmail/etc) or the Mail Transport/Submission Agents (any program that routes the message to you) could be stripping the data you want before you get it.

EmFi
That makes sense, except that the recipient obviously doesn't need to be blocked from seeing their own address. In this case, the destination address is appended with a "+" suffix that carries certain routing info required to process the email content. I'd like to be able to retain the destination address with the suffix intact without: (a) requiring the sender to use the TO field, and (b) using the CC field, as that would disclose the suffix to all other recipients.Perhaps this isn't possible?
Sol Irvine
I've edited my answer to address your address your concerns.
EmFi
Thanks. Your help is much appreciated!
Sol Irvine