This example shows how to add e-mail to Microsoft Outlook outbox using VB.Net
For this tip to work, the MS Outlook must be installed on the machine. And another important point here to get this code working is to add a reference to Microsoft Outlook Object Library x.o ,where x is the version of MS Outlook installed in the machine.
For Eg:
In case of Microsoft Outlook 2002, Add “Microsoft Outlook 10.0 object library” and Microsoft Outlook 2003, Add “Microsoft Outlook 11.0 object library” (Right click on the project -> Add References -> Select the COM tab -> Select “Microsoft Outlook x.0 object library)
vb.net code:
Try Dim ol As New Outlook.Application() Dim ns As Outlook.NameSpace Dim fdMail As Outlook.MAPIFolder ns = ol.GetNamespace("MAPI") ns.Logon(, , True, True) ´creating a new MailItem object Dim newMail As Outlook.MailItem ´gets defaultfolder for my Outlook Outbox fdMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox) ´assign values to the newMail MailItem newMail = fdMail.Items.Add(Outlook.OlItemType.olMailItem) newMail.Subject = "Subject" newMail.Body = "Body" newMail.To = "someone@somewhere.com" newMail.SaveSentMessageFolder = fdMail newMail.Send() Catch ex As Exception Throw ex End Try