VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,778 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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 = "******@somewhere.com"
newMail.SaveSentMessageFolder = fdMail
newMail.SaveAs(Environ("HOMEPATH") & "\My Documents\" & newMail.Subject & ".msg", Outlook.OlSaveAsType.olMSGUnicode)
How can i get the Subject Body from Database?
Hi Man Hin,
insert (after fdMail = ..) and try following code for SQL database. ConnectionString to SQL Server is set in project settings (cnSQL).
Try
Using cmd As New SqlCommand("SELECT * FROM Tab1", New SqlConnection(My.Settings.cnSQL))
cmd.Connection.Open()
Dim rdr = cmd.ExecuteReader
While rdr.Read
'assign values to the newMail MailItem '
newMail = CType(fdMail.Items.Add(Outlook.OlItemType.olMailItem), Outlook.MailItem)
newMail.Subject = rdr.GetString(0) ' 0 - munber of Field "Subject" in readed row '
newMail.Body = "Body"
newMail.To = "******@somewhere.com"
newMail.SaveSentMessageFolder = fdMail
newMail.SaveAs(Environ("HOMEPATH") & "\My Documents\ " & newMail.Subject & ".msg", Outlook.OlSaveAsType.olMSGUnicode)
End While
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try