0 votes
by (180 points)
edited

I am using the secure imap library to send e-mail through gmail via our in-house application. When the message is sent a cached copy is saved in what we call a library service. This serves to let us show all message interactions with a customer. I am even able to periodically connect to a user's account over imap and check for replies. This all works perfectly, but now I need to add the ability to save drafts.

I am able to save the draft just fine using the StoreMessage() method on Imap. Now the message is in Gmail under the Drafts folder, but my problem is knowing when that message is sent (and reconciling the message with my library service). The MessageId of my MailMessage is not the same as what is ultimately sent nor is the value returned from StoreMessage(). Now that I've gotten to this point I'm left inserting some text into the body of the draft that can be sent with the message and queried for. I am even fine with that, except I am lead to believe tools like SpamAssasin will look for tracking codes like that and likely flag my message as spam (is this a legit concern?).

Does anyone have experience solving a problem like this and if so what did you do?

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (73.5k points)
edited
 
Best answer

Unfortunately, it seems the Gmail reformat the whole message when it is sent from Draft. So some headers are removed, Message-Id header is changed, BodyHtml is reformatted.

The only place where to persist some kind of Guid to identify the message later seems to be Subject, Body and Attachments.

The following code finds the mail sent from Drafts:

// generate Guid to identify the message
string guid = Guid.NewGuid().ToString();

// prepare new draft
MailMessage mail = new MailMessage();
mail.To = "some@domain";
mail.Subject = "Test mail";
mail.BodyHtml = string.Format("This is a test <div style=color:white>{0}</div>", guid);

// store draft in Gmail Drafts
imap.StoreMessage("[Gmail]/Drafts", mail);

// do some other work, or persist the guid somewhere
// in the meantime, message is sent from [Gmail]/Drafts and moved to [Gmail]/Sent Mail

// search for the message identified with the Guid in Gmail Sent mails
imap.SelectFolder("[Gmail]/Sent Mail");
ImapMessageCollection col = imap.Search(ImapSearchParameter.Body(guid));
foreach (ImapMessageInfo item in col)
{
    Console.WriteLine(item.Subject);
}

Regarding tools like SpamAssassin, I don't think that one Guid within the Body will lead to flagging your mail as a spam. But it is possible that using white text on white background will be suspicious for SpamAssassin.

by (180 points)
edited

Thanks for the thoughts. I ended up doing pretty much this, minus the white text. I'm not too concerned if the recipient sees it. I also took the time to read through the docs on spam assassin and I think my initial concerns were probably overblown.

...