I'm fetching an email like so:
private static SmtpClient client = null;
client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential(email, password);
client.Timeout = 20000;
IEnumerable<uint> uids = client.Search(SearchCondition.Unseen());
Then iterate the uids, and for each:
MailMessage m = client.GetMessage(msgUID, FetchOptions.Normal);
client.SetMessageFlags(msgUID, null, MessageFlag.Seen);
string date = ((DateTime)m.Date()).ToString("g");
string body = m.Body;
My problem is that the message body isn't the body that is displayed in the actual email, it is completely different (and a body that doesn't appear in the email).
I'm thinking that perhaps the email's body is pulled dynamically, and replaces the content when you open the gmail message in the browser. The body that I do fetch doesn't appear to have any html or js in it.
I'll mention that if I forward this email to myself, and process that email the body's content is indeed the content I want.
Can that be? How do I discover if this is really the reason, and if so, how do I work around the problem to retrieve the actual text of the body?
Edit: When inspecting the MailMessage object in the debugger I can see that it has "AlternateView" of Count 1, not sure if that means that there's one view total or one view apart from what I pulled. I can't see any content there in the debugging tree.