【问题标题】:I want to add "CC" and Text in the body of this code. What should I do to add it?我想在这段代码的正文中添加 \"CC\" 和 Text。我应该怎么做才能添加它?
【发布时间】:2022-11-15 06:12:19
【问题描述】:

我已经能够根据需要创建自动电子邮件回复。但是,我想在电子邮件正文中添加文本并抄送以添加电子邮件地址。我应该如何添加它?

Sub FwdSelToAddr()
    Dim objOL As Outlook.Application
    Dim objItem As Object
    Dim objFwd As Outlook.MailItem
    Dim strAddr As String
    Dim objRecip As Outlook.Recipient
    Dim objReply As MailItem
    On Error Resume Next
    Set objOL = Application
    Set objItem = objOL.ActiveExplorer.Selection(1)
    If Not objItem Is Nothing Then
        strAddr = ParseTextLinePair(objItem.Body, "Email:")
        If strAddr <> "" Then
            Set objFwd = objItem.Forward
            objFwd.To = strAddr
            objFwd.Display
        Else
            MsgBox "Could not extract address from message."
        End If
    End If
    Set objOL = Nothing
    Set objItem = Nothing
    Set objFwd = Nothing
End Sub

这是我到目前为止所做的。我只想能够在自动回复的正文中添加抄送电子邮件地址和文本。

【问题讨论】:

    标签: vba outlook office365


    【解决方案1】:

    如果您需要修改或更新消息正文,则需要通过设置Cc 属性和HTMLBody 属性来稍微修改代码:

    If strAddr <> "" Then
      Set objFwd = objItem.Forward
      objFwd.To = strAddr
      objFwd.Cc = "email@address.com"
      objFwd.HTMLBody = "<b>Hello world</b>"
      objFwd.Display
    Else
    

    请注意,要保留原始电子邮件中的消息正文,您需要在开始 &lt;body&gt; 和结束 &lt;/body&gt; 标记之间插入内容。如果您需要在消息的开头添加附加文本,请将其粘贴在开始标记之后,如果您打算将其粘贴到消息的末尾 - 粘贴在结束标记之前。

    此外,您可能会发现 MailItem 类的 Recipients 属性很有帮助。它允许以更方便的方式设置 Outlook 项目的收件人。您可以在我为技术博客 - How To: Fill TO,CC and BCC fields in Outlook programmatically 撰写的文章中阅读有关该属性的更多信息。

    【讨论】:

      猜你喜欢
      • 2019-01-06
      • 2020-05-24
      • 2022-12-06
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 2020-09-16
      • 2016-07-13
      • 1970-01-01
      相关资源
      最近更新 更多