The code I am using at the moment is
try
{
//using MailKit.Net.Pop3;
string pathLog = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);
string fileNameLog = Path.Combine(pathLog, "pop3.txt");
using (var client = new Pop3Client(new ProtocolLogger(fileNameLog)))
//using (var client = new Pop3Client(new ProtocolLogger("pop3.log")))
{
strProgress = strProgress + "c";
client.Connect("outlook.office365.com", 995, SecureSocketOptions.SslOnConnect); //POP3 port is 995
strProgress = strProgress + "d";
client.Authenticate("xxx", "yyy");
strProgress = strProgress + "e";
for (int i = 0; i < client.Count; i++)
{
strProgress = strProgress + "f";
var message = client.GetMessage(i);
strProgress = strProgress + "g";
//Write the message to a file
message.WriteTo(string.Format("{0}.msg", i)); //<<<<<<<<<error here
numCountEmailsDownloaded = numCountEmailsDownloaded + 1;
}
client.Disconnect(true);
}
}
catch (Exception ex)
{
Toast.MakeText(this, ex.Message + "\n\nStopped after " + strProgress, ToastLength.Long).Show();
}
I get an error message which says 'Access to the path "/0.msg" is denied. Stopped after abcdefg (I use strProgress to mark where the error is).
I've tried getting the email body as a string but the error message says 'Do not use string to serialize ...use WriteTo instead', except that it doesn't tell me what to do with it even if it worked. The idea of receiving emails and then wanting to know what they say must be a common one, but many other questions and answers on the web seem to think it isn't worth actually spelling out. How can I extract the email body text from the above? Thank you.