发送时邮件正文丢失(outlook vba)

E-Mail body is lost when sending (outlook vba)

我正在尝试编写一个宏,在发送原始电子邮件之前向特定地址发送自动通知。 (就像 cc,但实际上没有使用 cc。)

应将原始格式化电子邮件的内容(包括文本、表格和图片)复制并粘贴到新电子邮件中,然后自动发送。当我只显示消息时一切正常,但在实际发送电子邮件时却没有。

这是我的代码:

Dim objMsg As Outlook.MailItem
Dim activeMailMessage As Outlook.MailItem
Dim BodyText As Object

' Create the message.
Set objMsg = Application.CreateItem(olMailItem)

'copy body of current item
Set activeMailMessage = ActiveInspector.CurrentItem
activeMailMessage.GetInspector().WordEditor.Range.FormattedText.Copy

'paste body into new email
Set BodyText = objMsg.GetInspector.WordEditor.Range
BodyText.Paste

'set up and send notification email
With objMsg
    .To = "test@domain.com"
    .Subject = "text" 
    .Send
End With

文本应该像这样粘贴到正文中,但不会粘贴:

With objMsg
    .To = "test@domain.com"
    .Subject = "test" 
    .body = bodytext.paste 
    .Send
End With

当我使用 .display 时,会显示正确的内容。但是当我直接发送它时(没有先使用 .display),所有信息都丢失了并且发送了一封空电子邮件。我能做什么?

我可以在原始电子邮件中添加密件抄送以获得相同的结果,但原始电子邮件并不总是发送,而此通知应该是。

尝试在调用 Paste 方法后调用 Save 方法。

您的代码实际上从未在 objMsg 对象中设置电子邮件的正文。当您显示 objMsg 时它正在工作,因为您与 'Inspector'.

进行交互

如果您直接在 objMsg 上设置 HTMLBody(如果您想保留格式)或 Body 属性,那么它将像下面的示例一样工作。

With objMsg
    .HTMLBody = activeMailMessage.HTMLBody
    .To = "test@domain.com"
    .Subject = "text" 
    .Send
End With

Bob,关于您提出的有关电子邮件中嵌入的图像因上述方法而丢失的问题。另一种解决方案是使用 MailItem 的 Copy 方法来创建与原始 Item 完全相同的新 MailItem。这还将保留向谁发送电子邮件,您需要清除此项以确保只有预期的收件人收到它。

Dim objMsg As Outlook.MailItem
Dim activeMailMessage As Outlook.MailItem

' Create the new message.
Set objMsg = Application.CreateItem(olMailItem)

' Assign the current item to activeMailMessage
Set activeMailMessage = ActiveInspector.CurrentItem

' Copy the current item to create a new message
Set objMsg = activeMailMessage.Copy

' Clear any existing recipients of the e-mail, as these will be retained in the Copy
While objMsg.Recipients.Count > 0
    objMsg.Recipients.Remove 1
Wend

'set up and send notification email
With objMsg
    .To = "test@domain.com"
    .Subject = "text" 
    .Send
End With

这应该保留原始电子邮件中的图像和其他附件。