We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting EML with attachments to PDF

I am trying to convert eml files to pdf that have attachments. The pdf is getting created but it only contains the body. What do I need to do to output email body and attachment into the pdf file?

using System;
using System.Diagnostics;
using System.IO;
using Aspose.Email;
using Aspose.Words;
using SaveOptions = Aspose.Email.SaveOptions;

namespace EmlToPdf
{
class Program
{
static void Main(string[] args)
{
var files = Directory.GetFiles(args[0], “*.eml”);
var outputDirectory = args[1];

		var stopwatch = new Stopwatch();
		stopwatch.Start();

		foreach (var file in files)
		{
			var message = MailMessage.Load(file);
			using (var ms = new MemoryStream())
			{
				var so = SaveOptions.CreateSaveOptions(MailMessageSaveType.MHtmlFormat);
				message.Save(ms, so);
				
				var loadOptions = new Aspose.Words.Loading.LoadOptions {LoadFormat = LoadFormat.Mhtml};

				var document = new Aspose.Words.Document(ms, loadOptions);

				var saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
				document.Save(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(file) + ".pdf"), saveOptions);
			}
		}

		stopwatch.Stop();
		Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);

	}
}

}

Note the eml file I am testing contains a pdf attachment.

@thayesxx

Can you please share the source file, generated PDF and desired output PDF. I will investigate that further on my end to help you out.

I have attached a zip with eml file, output pdf file (Email with pdf.pdf) and Invoice.pdf which is the attachment from the eml file. I also included my source file in the zip.
AsposeFiles.zip (184.6 KB)

Tim Hayes

@thayesxx

I have been able to reproduce the issue on my end. A ticket with ID EMAILNET-40313 has been created to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Thanks do you have an eta on the issue? I am just looking for a month or a quarter.

Is there another way I could accomplish this? I simply want to get eml and attachment converted to a standard format (e.g. pdf, word, etc)

Thanks in advance.

@thayesxx

We request for your patience and will share the good news with you as soon as the issue will be addressed.