I'm trying to pull out the subject and body of an email with .Net. It seems to go OK except for the text/html MessagePart. I'm not sure of the encoding etc - has anybody got this working OK? It errors for me when trying to convert.
Here is the raw string for the text/html Body Data
"PGRpdiBkaXI9Imx0ciI-dGV4dCBpbiBoZXJlPGJyPjwvZGl2Pg0K"
which throws an error.
"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."
Here is the code:
UsersResource.MessagesResource.GetRequest gr = gs.Users.Messages.Get(userEmail, TextBox1.Text);
gr.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
Message m = gr.Execute();
foreach (MessagePart p in m.Payload.Parts)
{
if (p.MimeType == "text/html")
{
try
{
byte[] data = Convert.FromBase64String(p.Body.Data);
string decodedString = Encoding.UTF8.GetString(data);
Response.Write(decodedString);
}
catch (Exception ex) { }
}
}
I'm getting the decoding wrong???
Thanks for your help.