I need all the text in the body for incoming email.
I tried:
var mesage = GetMessage(service, "me", 1);
Console.WriteLine(mesage.Snippet);
public static Message GetMessage(GmailService service, String userId, String messageId)
{
try
{
return service.Users.Messages.Get(userId, messageId).Execute();
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
return null;
}
But I am getting just snippet as shown in the screenshot.
Incoming mail to me: Result:
1) Your email is larger than 102KB. Gmail will automatically clip any messages that exceed that size. The limit is based on the content in the HTML code. This will include formatting, text, URLs (including link tracking and images) and more.
Looking at the documentation, Message.Snippet
only returns a short part of the message text. You should instead use Message.Raw
, or more appropriately, Message.Payload.Body
?
var message = GetMessage(service, "me", 1);
Console.WriteLine(message.Raw);
Console.WriteLine(message.Payload.Body.Data);
You should try both out and see what works best for what you're trying to do.
To get message.Raw
you need to pass a parameter, as stated in the docs:
Returned in messages.get and drafts.get responses when the format=RAW parameter is supplied.
If none of those things work, you could try iterating over the parts of the message to find your data:
foreach (var part in message.Payload.Parts)
{
byte[] data = Convert.FromBase64String(part.Body.Data);
string decodedString = Encoding.UTF8.GetString(data);
Console.WriteLine(decodedString);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With