The below code is working for CSV file but when we use the same code to read excel file it is returning different letters in the file
foreach (MimeAttachment attach in msg.Attachments)
{
if (attach.Filename != "")
{
//read data from attachment
string myString = attach.Body.Replace("=\r\n", ""); //to eliminate the '=\r\n' from email attachemnt
Byte[] b = GetBytes(myString);
// save attachment to disk
System.IO.MemoryStream mem = new System.IO.MemoryStream(b, false);
FileStream outStream = new FileStream(DownloadFilePath + "\\" + attach.Filename, FileMode.Create);
mem.WriteTo(outStream);
mem.Close();
outStream.Flush();
outStream.Close();
}
}
ex:
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAACAAAAiwAAAAAAAAAA
EAAAjQAAAAEAAAD+////AAAAAIgAAACMAAAA////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////8J
CBAAAAYFAGcyzQfJgAEABgYAAOEAAgCwBMEAAgAAAOIAAABcAHAACQAAYXNoYWFyIE0uICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
This works for me
or try this
How to save email attachments in C#