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:
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”)
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
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)()
'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")
Thank you for your reply. Actually, your code works the same as my code. That’s not what I want.
The MSG file has 2 attachments (bookmarkoutput and Bike PDF). After converting the MSG, I need to embed the 2 attachments with the MSG file. Currently, what you did is just download the attachment file separately, only the main MSG file is converted into PDF.
My need is to embed the attachment file with the MSG PDF file (i.e., FW.pdf).
Just check in GroupDoc viewer; I think GroupDoc viewer is your venture. Just upload the MSG file and see how it shows the MSG file and its attachments in PDF.
Note: We already tried GroupDoc viewer. This viewer only creates PNG and JS files from PDF, so that PDF has the MSG and its 2 attachments.
Example: Take your code.
'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")
Here Untitled.pdf is the main MSG content (like subject, attachment, Best Regards, etc.) and fileName is the attachment (bookmarkoutput and Bike PDF), and you embedded it with Untitled.pdf file, and finally, you get FW.pdf. But if you open FW.pdf, you can only see the MSG content; you can’t see bookmarkoutput and Bike content.
Why, after embedding the attachment file with the MSG file, can’t you view all the content?
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.
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 ?
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.
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())
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.