Search code examples
c#microsoft-graph-api.net-6.0.net-8.0

How to convert message to EML file


How to convert each Microsoft.Graph.Models.Message object from emailbox to EML file using C#?


Solution

  • For me, I use the code bellow.

    var mc = gsc.Users[primaryMail].Messages[item.Id].Content.GetAsync().GetAwaiter().GetResult();
    
    using (var fs = new FileStream(filepath + Path.DirectorySeparatorChar.ToString() + curFileName, FileMode.Create, FileAccess.Write))
    {
        mc?.CopyTo(fs);
    }
    ret = true;
    
    Thread.Sleep(1500);