views:

1051

answers:

3

I try to store a draft e-mail via IMAP to a folder running on MS Exchange. Everything ok, except that Bcc recipients don't get shown in the draft message stored on the server. Bcc recipients also don't receive the email if I send it with MS Outlook. If I read the message back with Python after I have stored it on the server, I can see the Bcc in the draft.

The following Python code reproduces this behavior:

import imaplib 
import time 
from email.MIMEMultipart import MIMEMultipart 
from email.MIMEText import MIMEText 

message = MIMEMultipart() 
message['Subject'] = 'Test Draft' 
message['From'] = '[email protected]' 
message['to'] = '[email protected]' 
message['cc'] = '[email protected]' 
message['bcc'] = '[email protected]' 
message.attach(MIMEText('This is a test.\n')) 

server= imaplib.IMAP4('the.ser.ver.ip') 
server.login('test', 'test') 
server.append("Drafts" 
              ,'\Draft' 
              ,imaplib.Time2Internaldate(time.time()) 
              ,str(message)) 
server.logout()

If I run this code, a draft gets stored into the Draft folder on the Exchange Server. But if I look at the draft with MS Outlook, it does not include the bcc recipient (message['bcc'] = '[email protected]'). Message, to, from, cc ok, no error.

If I download drafts that already include a bcc from an Exchange folder, I can also see the bcc. Only uploading doesn't work for me.

Any help very much appreciated. Thanks. BTW, MAPI is not an option.

Update: Thanks. X-Receiver didn't work for me. As for playing around with an IMAP-Folder in Outlook, I got an interesting result. If I access the draft via the IMAP-Folder in Outlook, I see the bcc. But if I access it via the MAPI-Folder, I don't see it. Will play a little bit around with that.

Conclusion: thanks for the input. Actually, the code works just fine. See below for the answer that I found.

+1  A: 

It could be that way by design. After all, the whole point of bcc is that the recipients are hidden from each other.

I understand that you are not sending the e-mail, just storing it. But my guess is that Exchange's internal rules kick in when the message is IMAP.appended to the folder, causing the bcc field to be stripped away.

Obviously, when messages are saved to a folder using Outlook the bcc field is not stripped away. But I guess outlook communicates with Exchange using some internal mechanizm (MAPI?).

All the above is just guesswork.

Something fun you could try:

  • In an empty Outlook/MAPI profile, create a IMAP account. Set it up to store Drafts and Sent Items on the Exchange server.
  • See if outlook using IMAP can save bcc of Drafts correctly.

I tried the above using the Evolution e-mail client connected to Exchange over IMAP. Using outlook (connected the normal way), I then had a look in Drafts and Sent Items. The bcc field was missing in both places.

I belive this supports my theory.

codeape
+1  A: 

Try setting this alternate version of the BCC header:

X-Receiver: [email protected]

Exchange in particular will treat this like a BCC when you send it. But I bet it will not strip it when you write via IMAP. You can include more than one BCC recipient by duplicating this line.

This is a complete hack, obviously.

Chase Seibert
+1  A: 

Actually, the code works just fine. It creates the proper mail with all the right headers including bcc.

How does the mail client display bcc?

The mail client (e.g. Python or MS Outlook via IMAP or MAPI in my case) decides whether and how to display bcc-headers. Outlook for example doesn't display bcc headers from an IMAP folder. This is a feature to hide bcc recipients from each other where they have not been stripped away from the mail before (it is not clear from the standard whether one bcc recipient is allowed to see all other bcc recipients or not, see Wikipedia).

Who handles bcc upon sending an email?

Suppose now that we have drafted a message in a mail client and stored it in an IMAP or MAPI folder. The server providing the IMAP / MAPI folders leaves the draft message unchanged. What happens to the bcc-headers upon sending the mail is implementation dependent, and might depend both on the mail client and the mail transfer agent (e.g. MS Exchange Server in my case). In a nutshell, people do not agree whether the mail client or the mail transfer agent is reponsible for removing bcc headers. It seems however to be the case that a majority of developers is of the opinion that it is the mail client's business with the mail transfer agent not touching the mail (e.g. MS Exchange, MS SMTP, Exim, OpenWave). In this case, the mail transfer agent sends the email to the recipient as defined in the RCPT TO: of the SMTP communication, and leaves the email unchanged otherwise. Some other mail transfer agents strip bcc headers from emails however (e.g. sendmail, Lotus Notes). A very thorough discussion can be found on the Exim mailing list here.

In the case of MS Outlook and MS Exchange, MS Outlook never sends bcc (but sends individual emails for each bcc recipient) and MS Exchange does not touch the email headers, but sends the full email (possibly including bcc recipients) to the recipients defined in RCPT TO:.

Conclusion

I did not understand that there is no guaranteed behavior for bcc, and that usually the client handles bcc. I will rewrite my Python code to loop over bcc recipients and generate one email for each bcc recipient.

stephan