Reputation: 793
How can I send a mail using MAPI with an HTML body? I need to create table in a message body. I'm using vb6 and the MAPI control. Any ideas?
Function MailSend(sSendTo As String, sSubject As String, sText As String) As Boolean
On Error GoTo ErrHandler
With MAPISession1
If .SessionID = 0 Then
.DownLoadMail = False
.LogonUI = True
.SignOn
.NewSession = True
MAPIMessages1.SessionID = .SessionID
End If
End With
With MAPIMessages1
.Compose
.RecipAddress = sSendTo
.AddressResolveUI = True
.ResolveName
.MsgSubject = sSubject
.MsgNoteText = sText
.Send False
End With
MailSend = True
Exit Function
ErrHandler:
'MsgBox Err.Description
MailSend = False
End Function
Upvotes: 2
Views: 7717
Reputation: 11
keep .MsgNoteText =""; .AttachmentPathName = result
ie.
With MAPIMessages1
.Compose
.RecipAddress = sSendTo
.AddressResolveUI = True
.ResolveName
.MsgSubject = sSubject
.MsgNoteText =""
.AttachmentPathName = "c:\yourHtml.html"
.Send False
End With
Upvotes: 1
Reputation: 66316
MAPI control uses Simple MAPI, which does not handle HTML. There is a trick when using Simple MAPI directly (MAPISendMail) - set the body to NULL and attach and HTML file: it will be used as the message body. I don't know if that trick will work with the MAPI control.
Why not switch to using the Outlook Object Model? It is perfectly capable of handling HTML:
set App = CreateObject("Outlook.Application")
set NS = App.GetNmaespace("MAPI")
NS.Logon
set Msg = App.CreateItem(0)
Msg.To = sSendTo
Msg.Subject = sSubject
Msg.HTMLBody = sYourHTMLBody
Msg.Send 'or Msg.Display
Upvotes: 5