I'm trying to parse the last unread message from gmail, but for some reason my code fails while the formatting of the message is a bit different.
When I manually send the message to the email, this code works. In this case, the mail looks like that: Picture
The code itself looks like that:
public static int GetMail()
{
//OTP READ FROM GMAIL
var client = new Pop3Client();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("MAIL@gmail.com", "PASSWORD");
var count = client.GetMessageCount();
Message messages = client.GetMessage(count);
MessagePart plainTextPart = messages.FindFirstPlainTextVersion();
string message = plainTextPart.GetBodyAsText();
string resultString = Regex.Match(message, @"\d+").Value;
int Mail = Int32.Parse(resultString);
client.DeleteAllMessages();
client.Disconnect();
return Mail;
}
But when I install an app on my cellphone (which automatically forwards new messages to your email), the application change the message formatting and email message looks like that: Picture 2
As it seems, when the email message formatting changes, it doesn't work anymore. Could you guys please give me suggestion of how to modify the code so it works with the formatting given in Picture 2.