Converting TXT to EML missing subject/from/to

If I save an e-mail from Outlook or Thunderbird as TXT and later want to convert it back into MSG or EML, the INformation subject/from/to is missing in the created mail file. Is there a solution for this, so that I get this information displayed as in the original mail?Missing_header.jpg (28.1 KB)

Hello @hova45,

Aspose.Email doesn’t support loading messages from TXT files.
But you can write a simple parser to convert TXT to EML or MSG.

For example:

TXT file with the following content:

From: some value
Date: some value
To: some value
Subject: some value

Some body

The example code to parse TXT file and convert to eml and msg:

var lines = File.ReadAllLines(@"test.txt", Encoding.UTF8);

var from = lines.FirstOrDefault(l => l.StartsWith("From:", StringComparison.OrdinalIgnoreCase))?.Substring(6);
var date = lines.FirstOrDefault(l => l.StartsWith("Date:", StringComparison.OrdinalIgnoreCase))?.Substring(6);
var to = lines.FirstOrDefault(l => l.StartsWith("To:", StringComparison.OrdinalIgnoreCase))?.Substring(4);
var subject = lines.FirstOrDefault(l => l.StartsWith("Subject:", StringComparison.OrdinalIgnoreCase))?.Substring(9);
var body = string.Join(Environment.NewLine, lines.SkipWhile(l => !string.IsNullOrWhiteSpace(l)).Skip(1));

var eml = new MailMessage()
{
    Subject = subject,
    From = from,
    To = to,
    Date = DateTime.Parse(date),
    Body = body
};


eml.Save(@"test.eml", SaveOptions.DefaultEml);
eml.Save(@"test.msg", SaveOptions.DefaultMsg);