How to attach .HTML file to Outlook body

yugandhar

Member
Joined
Jun 3, 2007
Messages
6
Programming Experience
Beginner
hi,
I am working an App, where i have to attach a .HTML file to the body of outlook application,
when i am try to do that it is showing the tags aslo inthe body of the outlook,
please any one can help me on that,
my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oOutlook As New Outlook.Application
'Dim oOutlookitem As Outlook.MailItem
Dim olApp As Outlook.ApplicationClass = New Outlook.ApplicationClass
Dim olexp As Outlook.Explorer
'Create th Namespace Object
Dim olNS As NameSpaceClass = olApp.GetNamespace("Mapi")
'Logon to Outlook if it's not running
'The Profilename is "Outlook", password ""
''olNS.Logon("Outlook", "", False, False)
'Create a new Mailitem (in the Draftsfolder)
'''Dim objMail As MailItem = olApp.CreateItem(OlItemType.olMailItem)
olexp = olApp.CreateItem(OlItemType.olMailItem)
' The mail to line is not required as the client wants to enter the email address

' manually.

'objMail.To = ""
olexp.Subject = "sample email"
olexp.HTMLBody = olexp.BodyFormat
olexp.Body = ltr()
'objMail.Save()
olexp.Display()
'Logoff from Session
''olNS.Logoff()
'Release Marshal-Com Objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(olexp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(olNS)
System.Runtime.InteropServices.Marshal.ReleaseComObject(olApp)
End Sub
Private Function ltr() As String
Dim sr As StreamReader
sr = File.OpenText("D:\Documents and Settings\Yogi\Desktop\Letters.html")
Dim _filetext As String = sr.ReadToEnd()
sr.Close()
'Now we need to insert the dates.
_filetext.Replace("<insert date>", System.DateTime.Today.Date.ToString())
_filetext.Replace("<Insert first Monday after sign off>", System.DateTime.Today.Date.ToString())
Return _filetext
End Function
 
Email is complicated and sometimes requires recursive calls to get through
it all. Your html may need to be placed somewhere other than the body.
 
Yes, I've described this in your other post Yugandhar.

It should be

VB.NET:
Expand Collapse Copy
olexp.BodyFormat = OlBodyFormat.olFormatHTML
olexp.HTMLBody = ltr()

Again, the same as in your other post use .HTMLBody
 
Last edited:
Back
Top