How to convert .eml-.msg to pdf file?

Hi


1. I am using Aspose.Total api for .net with temporary license,i need to convert eml,msg to pdf file.Pls reply in vb coding.

2.I need a one document which ,those format can convert into pdf ,just i need supporting format only to pdf like,doc,docx,txt,ppt .
If u give with api ,its better to understand like

Aspose.Words
Doc,docx,txt,xml

Aspose.Cells
xls,xlsx

Aspose.PDF
jpg,tif,png

Note: i need only supporting format to convert to pdf.not convert to any other format.

Regards
Aravind

Hi Aravind,

Thank you for considering Aspose line of products.

1. For converting EML or MSG to PDF, please have a look at our documentation article Saving a MSG as PDF which uses Aspose.Email in combination with Aspose.Words to achieve this goal.

2. For other conversions, please visit the following pages:

In case you have any other query/inquiry in this regard, please feel free to write to us back.

Hi

Thank u for ur reply,now can convert msg,eml to pdf


Regards
Aravind

Hi Arvind,

If you want to convert email message to PDF with attachments, you will have to first extract attachments from email messages using Aspose.Email and then add attachments to PDF using Aspose.Pdf after converting email message to PDF.

Best Regards,

Hi

Can u check my code reply,i am going to open msg file with attachment to pdf format.
So first i download the attachment form msg file,then i go to convert msg file to pdf and add the attachment with pdf file. below is my code,after convert msg with attachment to pdf i cant open pdf file.pls try ur msg file with attachment and reply me.
Note: I am not include temporary license.

Dim mailMsg As Aspose.Email.Mail.MailMessage = Aspose.Email.Mail.MailMessage.Load(“D:\doc\FW CIO Summit Event.msg”, Aspose.Email.Mail.MessageFormat.Msg)

Dim attachment As Aspose.Email.Mail.Attachment
For Each attachment In mailMsg.Attachments
'To display the the attachment file name
attachment.Save(“D:\doc” & attachment.Name)
Next

Dim pdfDocument As New Aspose.Pdf.Document(“D:\doc\FW CIO Summit Event.msg”)
Dim fileSpecification As New FileSpecification(“D:\doc”& attachment.Name, “Sample text file”) 'Here attachment.name is attachment pdf file,i will try like this for testing Dim fileSpecification As New FileSpecification(“D:\doc\Test.txt”, “Sample text file”)
pdfDocument.EmbeddedFiles.Add(fileSpecification)
pdfDocument.Save(“D:\doc\FW CIO Summit Event.pdf”)

But after convert FW CIO Summit Event.pdf (using its own attachment or i add attachment .txt file) i could not open pdf file.

Pls check this code is correct or not,if not give correct code.


Hi pls leave it above code This is my modified code pls check this

Here first i convert msg to pdf file in this name FW CIO Summit Event.pdf

Dim mailMsg As Aspose.Email.Mail.MailMessage = Aspose.Email.Mail.MailMessage.Load(“D:\doc\FW CIO Summit Event.msg”)

Dim ms As New MemoryStream()

'Save as MHTML
mailMsg.Save(ms, MailMessageSaveType.MHtmlFromat)

'create an instance of LoadOptions and set the LoadFormat to Mhtml
Dim loadOptions = New Aspose.Words.LoadOptions()
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml

'create an instance of Document and load the MTHML from MemoryStream
Dim document = New Aspose.Words.Document(ms, loadOptions)

'create an instance of HtmlSaveOptions and set the SaveFormat to Html
Dim saveOptions = New Aspose.Words.Saving.PdfSaveOptions()

'save the document to Html file
document.Save(“D:\doc\FW CIO Summit Event.pdf”, saveOptions)


Secondly,Here download attachment file form msg file and saved as aaa.pdf

Dim mailMsg1 As Aspose.Email.Mail.MailMessage = Aspose.Email.Mail.MailMessage.Load(“D:\doc\FW CIO Summit Event.msg”, Aspose.Email.Mail.MessageFormat.Msg)

Dim attachment As Aspose.Email.Mail.Attachment
For Each attachment In mailMsg1.Attachments
'To display the the attachment file name
attachment.Save(“D:\doc\aaa.pdf”)
’ Console.WriteLine(attachment.Name)
Next

Finally,here i am add attachment to pdf(i.e.
FW CIO Summit Event.pdf(this is msg file) and add aaa.pdf(this attachment file) and final pdf saved as FW.pdf ,if i open FW.pdf i only see msg content ,not added attachyment file
)

'open document
Dim pdfDocument As New Aspose.Pdf.Document(“D:\doc\FW CIO Summit Event.pdf”)
'setup new file to be added as attachment
Dim fileSpecification As New FileSpecification(“D:\doc\aaa.pdf”, “Sample text file”)
'add attachment to document’s attachment collection
pdfDocument.EmbeddedFiles.Add(fileSpecification)
'save new output
pdfDocument.Save(“D:\doc\FW.pdf”)

Pls try ur msg file with attachment in this code.

Note : i am use latest API for Words,Email.
Pls reply asap

Regards
Aravind


Hi Arvind,


Thanks for your inquiry. We are looking into your scenario and will get back to you soon.

Best Regards,

Hi Arvind,


We have tested the scenario with a sample MSG file will attachments, but unable to notice the issue. Please find enclosed sample files and code used for reference. Please share your sample source MSG file, we will test the scenario at our end and will guide you accordingly.


Dim attFileName As New List(Of String)()<o:p></o:p>

'Convert MSG to MHTML

Dim mailMsg As Aspose.Email.Mail.MailMessage = Aspose.Email.Mail.MailMessage.Load(myDir + "Untitled.msg")

Dim ms As New MemoryStream()

'Save as MHTML

mailMsg.Save(ms, MailMessageSaveType.MHtmlFromat)

'Convert MHTML to PDF

'create an instance of LoadOptions and set the LoadFormat to Mhtml

Dim loadOptions = New Aspose.Words.LoadOptions()

loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml

'create an instance of Document and load the MTHML from MemoryStream

Dim document = New Aspose.Words.Document(ms, loadOptions)

'create an instance of HtmlSaveOptions and set the SaveFormat to Html

Dim saveOptions = New Aspose.Words.Saving.PdfSaveOptions()

'save the document to Html file

document.Save(myDir + "Untitled.pdf", saveOptions)

'Extract attachments from MSG

Dim mailMsg1 As Aspose.Email.Mail.MailMessage = Aspose.Email.Mail.MailMessage.Load(myDir + "Untitled.msg", Aspose.Email.Mail.MessageFormat.Msg)

Dim attachment As Aspose.Email.Mail.Attachment

For Each attachment In mailMsg1.Attachments

'To display the the attachment file name

attachment.Save(myDir + attachment.Name)

attFileName.Add(myDir + attachment.Name)

Next

'Add Attachments to final PDF

'open document

Dim pdfDocument As New Aspose.Pdf.Document(myDir + "Untitled.pdf")

For Each fileName As String In attFileName

'setup new file to be added as attachment

Dim fileSpecification As New FileSpecification(fileName, "Sample text file")

'add attachment to document's attachment collection

pdfDocument.EmbeddedFiles.Add(fileSpecification)

Next

'save new output

pdfDocument.Save(myDir + "FW.pdf")

We are sorry for the inconvenience caused.


Best Regards,

Hi

Thank u for ur reply,actually your code work same as my code.i dont want like that.

Actually msg file have 2 attachment(bookmarkoutput and Bike pdf) after convert msg need to embed 2 attachment with msg file,But currently what u did,u just download attachment file separately ,only main msg file only converted into pdf.
My need is need embed attachment file with msg pdf file(i.e FW.pdf)

Just check in GroupDoc viewer,i think GroupDoc viewer is ur venture,just upload msg file and see ,how it show msg file and following its attachment in pdf.


Note: We already try gropdoc viewer,that viewer only create png and js file form pdf ,So that pdf have msg and its 2 attachments.

Example:Take ur code

’open document<o:p></o:p>

Dim pdfDocument As New Aspose.Pdf.Document(myDir + “Untitled.pdf”)<o:p></o:p>

For Each fileName As String In attFileName<o:p></o:p>

'setup new file to be added as attachment<o:p></o:p>

Dim fileSpecification As New FileSpecification(fileName, “Sample text file”)<o:p></o:p>

'add attachment to document’s attachment collection<o:p></o:p>

pdfDocument.EmbeddedFiles.Add(fileSpecification)<o:p></o:p>

Next<o:p></o:p>

'save new output<o:p></o:p>

pdfDocument.Save(myDir + “FW.pdf”)


Here Untitled.pdf is main msg content(like subject,attachment,Best Regards ect) and fileName is attachment(bookmarkoutput and Bike pdf) and u embedded with Untitled.pdf file and finally u get FW.pdf.But if open FW.pdf only can see msg content,cant see bookmarkoutput and Bike content.

Why after embedded attachment file with msg file cant view the all content.


Regards
Aravind

Hi Aravind,


Thanks for sharing additional information about your requirements. To accomplish your requirement you need to use concatenation feature, concatenate PDF file attachments to main MSG contents. Please check following documentation link for the details, it will help to fulfill your requirements.

Moreover, please note if your attachment file format is other than PDF then you have to convert it to PDF file format first, using related Aspose API before concatenation process.


Please feel free to contact us for any further assistance.

Best Regards,

Hi

Thank u for ur reply,now it work with concatenate method,But what the different embedded and concatenate ,both are combined one pdf to another pdf file.Why Embedded not work ? what purpose use embedded ?




Regards
Aravind

Hi Aravind,


Thank for your feedback. It is good to know that you have managed to accomplish the task. Please note EmbeddedFiles method embed actual file(text/images/PDF/DOC/XLS/…etc) of any format to PDF as attachment in PDF file resources. Whereas concatenation process merges pages of source PDF file to Parent PDF file. Hopefully it will clear the difference in both features.

Please feel free to contact us for any further assistance.

Best Regards,

I can see that I can use Aspose to convert .msg. can it also convert .eml to PDF through a VB.net API?


Regards
Steven

Hi Steven,


The MailMessage class can be used to load MSG as well as EML file formats. Thus, you can use it to convert the EML to PDF as well as shown in the following code sample.

Code:

Dim mailMsg As MailMessage = MailMessage.Load(“About Aspose-1.eml”, New EmlLoadOptions())


Dim ms As New MemoryStream()


'Save as MHTML

mailMsg.Save(ms, Aspose.Email.Mail.SaveOptions.DefaultMhtml)


'create an instance of LoadOptions and set the LoadFormat to Mhtml

Dim loadOptions = New Aspose.Words.LoadOptions()

loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml


’create an instance of Document and load the MTHML from MemoryStream

Dim document = New Aspose.Words.Document(ms, loadOptions)


'create an instance of HtmlSaveOptions and set the SaveFormat to Html

Dim saveOptions = New Aspose.Words.Saving.PdfSaveOptions()


'save the document to Html file

document.Save(“About Aspose.pdf”, saveOptions)