2013-04-05 40 views
2

如何使用MAPI和HTML正文發送郵件?我需要在消息體中創建表。 我正在使用vb6和MAPI控件。有任何想法嗎?使用VB6中的MAPI控件發送帶HTML內容的郵件

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 

回答

4

MAPI控件使用簡單的MAPI,它不處理HTML。直接使用簡單MAPI(MAPISendMail)時有一個技巧 - 將主體設置爲NULL並附加HTML文件:它將用作郵件正文。我不知道該技巧是否可以與MAPI控件配合使用。

爲什麼不切換到使用Outlook對象模型?這是完全有能力處理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 
+0

「將body設置爲NULL並附加HTML文件」得到我需要的:)謝謝。喜歡這個論壇。 – babboon 2013-04-06 07:20:24

1

保持 .MsgNoteText = 「」; 。附加路徑名稱=結果

即,

With MAPIMessages1 
    .Compose 
    .RecipAddress = sSendTo 
    .AddressResolveUI = True 
    .ResolveName 
    .MsgSubject = sSubject 
    .MsgNoteText ="" 
    .AttachmentPathName = "c:\yourHtml.html" 
    .Send False 
End With 
相關問題