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
Here is the code I ended up using:
foreach (MessagePart p in m.Payload.Parts)
{
if (p.MimeType == "text/html")
{
byte[] data = FromBase64ForUrlString(p.Body.Data);
string decodedString = Encoding.UTF8.GetString(data);
Response.Write(decodedString);
}
}
....
public static byte[] FromBase64ForUrlString(string base64ForUrlInput)
{
int padChars = (base64ForUrlInput.Length % 4) == 0 ? 0 : (4 - (base64ForUrlInput.Length % 4));
StringBuilder result = new StringBuilder(base64ForUrlInput, base64ForUrlInput.Length + padChars);
result.Append(String.Empty.PadRight(padChars, '='));
result.Replace('-', '+');
result.Replace('_', '/');
return Convert.FromBase64String(result.ToString());
}
Good article http://www.codeproject.com/Tips/76650/Base-base-url-base-url-and-z-base-encoding