9,779 questions
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