繁体   English   中英

将非 HTML 正文与 HTML 签名相结合

[英]Combining Non-HTML Body with HTML Signature

我尝试了所有不同的解决方案来解决这个问题: 如何在 Outlook 中添加默认签名
我没有发现任何适用于我所构建的东西。

我正在使用 Ron de Bruin 的 email 模板工作表的改编版,其中 email 正文和收件人正在引用另一个表。
我得到的 email 正文格式正确(新行分隔),签名损坏(包含链接和图像)或签名正确,但 email 正文格式不正确。

以下正确显示了签名,但 email 正文的格式不正确。

On Error Resume Next

Set olApp = Outlook.Application

Set olMail = olApp.CreateItem(olMailItem)
With olMail
    .display
End With

signature = olMail.HTMLbody

With olMail
    signature = olMail.HTMLbody
    
    .To = StringTo
    .CC = StringCC
    .BCC = StringBCC
    .Subject = Me.Cells(myCell.Row, "I").Value
    .HTMLbody = strHTMLBody & Me.Cells(myCell.Row, "K").Value & signature

试试下面的子。 该子将显示带有默认签名的邮件,您可以根据需要添加正文和附件。

Sub SendMailWithDefaultSign()
On Error GoTo HarunErrHandler
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim strAttachment As Variant, strSubject As Variant, strBody As Variant
Dim strEmail As String
Dim fileName As String

strSubject = "VBA code to send mail with default signature." 'Me.TaskID & ": " & Me.TaskTitle
'strBody = Me.Description
strEmail = "recipientmail@domain.com"

Set oEmail = oApp.CreateItem(olMailItem)
    
    With oEmail
        .BodyFormat = olFormatHTML
        .Display
        .Recipients.Add strEmail
        .Subject = strSubject
        .HTMLBody = "<b>Hello Everyone,</b><br>" & _
                    "Please cehck the attached file.<br>" & .HTMLBody
        
'        .Attachments.Add fileName
    End With

Exit Sub
HarunErrHandler:
MsgBox "Error :" & Err.Number & ", " & Err.Description, vbInformation, "Error"
End Sub

您需要确保将格式正确的 HTML 字符串分配给HTMLBody属性。 因此,如果您想在签名之前插入任何内容,您需要找到一个开始的<body>标记并将您的字符串粘贴到<body>标记之后。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM