Thanks this code works for me as well, but i have another challenge to convert .msg, any idea if i can add “.msg” as well in the same Case “.png”, “.jpg”, “.jpeg”, “.bmp”, “.tif”, “.msg” because if i m doing it it throws an error with “Parameter is not valid”.
i want to use “.msg” with this method because in the other method it ask me to save it by dialog box which i want to bypass
Given method will not work for MSG files. .NET doesn’t know how to render “picture” from the MSG file.
There is a way how to print MSG using microsoft.interop
The second variant might be adjusted to export into PDF
Cheers
no i think there is a way to do that, i had that code initially and runs fine, the only point was that i wanted to bypass the saveas dialog box but seems i need to manage it. not possible to save .msg file without prompting this dialog box
u also can try this msg to pdf code below
Try
Dim psi As New System.Diagnostics.ProcessStartInfo()
Dim filepath = Inputfile
psi.UseShellExecute = True
psi.Verb = “print”
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.FileName = filepath
Dim myProcess As System.Diagnostics.Process
myProcess = System.Diagnostics.Process.Start(psi)
myProcess.WaitForInputIdle()
Dim localProces As Diagnostics.Process = Diagnostics.Process.GetProcessById(myProcess.Id)
localProces.CloseMainWindow()
localProces.Close()
Catch ex As Exception
'MessageBox.Equals(ex.Message())
End Try
Your inital question was how to bypass the saveas dialog.
The follwoing code can do that with limitation that it will not contain e-mail header, only the body
Dim objOutlook As microsoft.Office.Interop.Outlook.Application
Dim objMsg As microsoft.Office.Interop.Outlook.MailItem
Dim objOutlookDoc As microsoft.Office.Interop.Word.Document
Dim inputFile As String = io.Directory.GetCurrentDirectory + "\sample.msg"
Dim outputFile As String = io.Directory.GetCurrentDirectory + "\sample.pdf"
objOutlook = New microsoft.Office.Interop.Outlook.Application
objMsg = CType(objOutlook.CreateItemFromTemplate(inputFile), MailItem)
' get MGS body
objOutlookDoc = CType(objMsg.GetInspector.WordEditor,microsoft.Office.Interop.Word.Document)
objOutlookDoc.ExportAsFixedFormat(OutputFileName:=outputFile, ExportFormat:=microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF)
thanks for the code but dint work for me see the error below.