- Imports Microsoft.Office.Interop
- 'this example need reference of microsoft word object library and outlook object library
-
- Public Class Form1
-
- Private oMissing As Object = System.Reflection.Missing.Value
-
- Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
- Dim strSubject As String = "subject test"
- Dim strMessage As String = "message test"
- Dim astrRecip As String = "recipientMe@mail.org"
- Dim astrAttachments As String = txtPath.Text
-
- Dim OutlookApp As New Outlook.Application
- Dim MyEMail As Outlook.MailItem = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
-
- For Each Recipient As String In Split(astrRecip, ";") : MyEMail.Recipients.Add(Recipient) : Next
- For Each Attachment As String In Split(astrAttachments, ";") : MyEMail.Attachments.Add(Attachment) : Next
-
- MyEMail.Subject = strSubject
- MyEMail.HTMLBody = getWordDoc(astrAttachments)
-
- MyEMail.Display()
- End Sub
-
- Private Function getWordDoc(ByVal filename As String) As Object
- Dim wordApp As Word.Application = New Word.ApplicationClass()
- Dim wordDoc As Word._Document
- Dim content As Object = ""
-
- wordApp.Visible = False
-
- wordDoc = wordApp.Documents.Open(CType(filename, Object), oMissing, True, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
-
- wordDoc.Content.Select()
- wordDoc.Content.Copy()
-
- Dim objClipboard As IDataObject = Clipboard.GetDataObject()
- If objClipboard.GetDataPresent(DataFormats.Html) Then content = objClipboard.GetData(DataFormats.Html)
-
- wordApp.Quit(CType(False, Object), oMissing, oMissing)
-
- wordDoc = Nothing
- wordApp = Nothing
- Return content
- End Function
- End Class
Imports Microsoft.Office.Interop
'this example need reference of microsoft word object library and outlook object library
Public Class Form1
Private oMissing As Object = System.Reflection.Missing.Value
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
Dim strSubject As String = "subject test"
Dim strMessage As String = "message test"
Dim astrRecip As String = "recipientMe@mail.org"
Dim astrAttachments As String = txtPath.Text
Dim OutlookApp As New Outlook.Application
Dim MyEMail As Outlook.MailItem = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
For Each Recipient As String In Split(astrRecip, ";") : MyEMail.Recipients.Add(Recipient) : Next
For Each Attachment As String In Split(astrAttachments, ";") : MyEMail.Attachments.Add(Attachment) : Next
MyEMail.Subject = strSubject
MyEMail.HTMLBody = getWordDoc(astrAttachments)
MyEMail.Display()
End Sub
Private Function getWordDoc(ByVal filename As String) As Object
Dim wordApp As Word.Application = New Word.ApplicationClass()
Dim wordDoc As Word._Document
Dim content As Object = ""
wordApp.Visible = False
wordDoc = wordApp.Documents.Open(CType(filename, Object), oMissing, True, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
wordDoc.Content.Select()
wordDoc.Content.Copy()
Dim objClipboard As IDataObject = Clipboard.GetDataObject()
If objClipboard.GetDataPresent(DataFormats.Html) Then content = objClipboard.GetData(DataFormats.Html)
wordApp.Quit(CType(False, Object), oMissing, oMissing)
wordDoc = Nothing
wordApp = Nothing
Return content
End Function
End Class