How to create msg file?

rudba

Member
Joined
Jan 15, 2009
Messages
5
Programming Experience
Beginner
Hi guys,

How do i create msg file (Outlook file). The contain comes from database (from, to, subject, body etc)
 
Here is an example creating a Outlook MailItem and saving it as .msg file format:
VB.NET:
'Imports Outlook = Microsoft.Office.Interop.Outlook

Dim app As New Outlook.Application
Dim mi As Outlook.MailItem = CType(app.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
mi.To = "test@some.com"
mi.Subject = "some subject"
mi.Body = "hello Outlook message"
Dim path As String = IO.Path.Combine(Application.StartupPath, "test.msg")
mi.SaveAs(path, Outlook.OlSaveAsType.olMSG)
app.Quit()
The code requires Outlook and the Office PIA to be installed, in project add reference to the Microsoft Outlook Object library of appropriate version in COM tab.
 
Back
Top