在 Outlook 2010 中转发电子邮件及其附件 [英] Forward Email with its attachment in Outlook 2010

查看:37
本文介绍了在 Outlook 2010 中转发电子邮件及其附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码(我从几个来源中提取)现在可以工作,当我收到一封主题行中包含特定词的电子邮件时,它会触发一个运行以下内容的脚本.

The below code (I pulled from several sources) now works in that when I receive an email with specific words in the subject line it triggers a script that runs the below.

此代码然后保留主题行,在消息正文中添加文本并转发给预期的收件人.

This code then keeps the subject line, adds text the message body and the forwards to the intended recipient.

但是,如果我收到的电子邮件带有附件,则代码不再转发任何内容.我也需要它来转发通过电子邮件发送给我的附件(仅使用代码向电子邮件正文添加文本,否则我只需设置规则).

However, if the email I receive has an attachment the code no longer forwards anything. I need it to forward the attachment that was emailed to me as well (only using the code to add text to body of email otherwise I would just set a rule).

代码如下:

Sub ForwardEmail(item As Outlook.MailItem)
Dim oExplorer As Outlook.Explorer
Dim oMail As MailItem
Set oExplorer = Application.ActiveExplorer

On Error GoTo Release

If oExplorer.Selection.item(1).Class = olMail Then
Set oMail = item.Forward
oMail.Subject = oMail.Subject
oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add "email address here"


oMail.Save
oMail.Send

End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub

推荐答案

代码中不需要使用Explorer对象:

There is no need to use the Explorer object in the code:

Sub ForwardEmail(item As Outlook.MailItem)
  Dim oMail As MailItem    

  On Error GoTo Release

  If item.Class = olMail Then
     Set oMail = item.Forward
     oMail.Subject = oMail.Subject
     oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
     oMail.Recipients.Add "email address here"

     oMail.Save
     oMail.Send
  End If
 Release:
  Set oMail = Nothing
  Set oExplorer = Nothing
End Sub

您可能会找到入门在 Outlook 2010 中使用 VBA 文章很有帮助.

You may find the Getting Started with VBA in Outlook 2010 article helpful.

这篇关于在 Outlook 2010 中转发电子邮件及其附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆