Outlook VBscript转发文件夹中的电子邮件 [英] Outlook VBscript to forward emails in a folder
问题描述
我有一个特定的用户,他真的希望能够将任何电子邮件重定向到其部门中的其他人,以便当该人回复电子邮件时,该电子邮件将返回给最初发送该电子邮件的人.
I have a specific user that really wants to be able to redirect any email to other people in their department so that when that person replies to the email it will go back to the person who originally sent it.
我们不能授予他们所有人发送的权限,因为不是所有用户都是内部用户,因此我试图使VBScript在Outlook中运行,以便在指定的文件夹中转发所有电子邮件,但更改回复地址,以便他们不必每次都手动将其放入.
We can't give them permissions to send as everyone because not all users are internal so I am trying to make a VBScript to run in Outlook that will send forward all emails in a specified folder but change the reply address so that they don't have to manually put it in every time.
我是VB脚本的新手,所以我可能缺少一些基本的东西.
I'm fairly new to VB scripts so it's probably something pretty basic that I am missing.
这是我正在尝试的方法,但是不起作用:
This is what I am trying but it doesn't work:
Sub SendFolder()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim MyFolder As Outlook.MAPIFolder
Dim ObjMail As Outlook.MailItem
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set MyFolder = Application.Session.Folders("me@us.com").Folders("test")
For i = MyFolder.Items.Count To 0 Step -1
Set ObjMail.Subject = MyFolder.Itmes(i).Subject
Set ObjMail.ReplyRecipients = MyFolder.Itmes(i).ReplyRecipients
Set ObjMail.Body = MyFolder.Itmes(i).Body
Set ObjMail.Attachments = MyFolder.Itmes(i).Attachments
Set ObjMail.BodyFormat = MyFolder.Itmes(i).BodyFormat
Set ObjMail.To = "test@us.com"
ObjMail.Send
Next
End Sub
推荐答案
您丢失了
设置ObjMail = Application.CreateItem(olMailItem)
Set ObjMail = Application.CreateItem(olMailItem)
然后您的代码将变为
With ObjMail
.Subject = MyFolder.Itmes(i).Subject
.ReplyRecipients = MyFolder.Items(i).ReplyRecipients
.Body = MyFolder.Items(i).Body
.Attachments = MyFolder.Items(i).Attachments
.BodyFormat = MyFolder.Items(i).BodyFormat
.To = "test@us.com"
.Send
End with
它现在运行,ReplyTo不变.
It it runs now, the ReplyTo does not change.
您将要设置ObjMail的ReplyRecipients属性
You will want to set the ObjMail's ReplyRecipients property
类似于.ReplyRecipients.Add MyFolder.Items(i).SenderEmailAddress
Something like .ReplyRecipients.Add MyFolder.Items(i).SenderEmailAddress
为简化此问题,请按原样转发邮件,并仅设置ReplyRecipients属性.
To simplify the issue, .Forward the mail as is, and set only the ReplyRecipients property.
查看此替代方法.邮件作为附件发送.收件人会自动回复原始发件人.
Check out this alternative. The mail is sent as an attachment. The receiver automatically replies to the original sender.
未经测试
Sub SendFolderItemsAsAttachments()
' Run this VBA code while in Outlook
Dim MyFolder As MAPIFolder
Dim notMyItems as Items
Dim notReplyingToMe as mailitem
Dim i as long
Set MyFolder = Application.Session.Folders("me@us.com").Folders("test")
Set notMyItems = MyFolder.Items
For i = notMyItems.Count To 1 Step -1
If TypeOf notMyItems(i) Is MailItem Then
Set notReplyingToMe = Application.CreateItem(olMailItem)
With notReplyingToMe
.Subject = notMyItems(i).Subject & " - " & _
notMyItems(i).SenderName
.HTMLBody = "Redirecting for your action."
.Attachments.Add notMyItems(i), olEmbeddeditem
.To = "test@us.com"
.Send
End With
notMyItems(i).Delete
End If
Next
Set MyFolder = = Nothing
Set notMyItems = Nothing
Set notReplyingToMe = Nothing
End Sub
这篇关于Outlook VBscript转发文件夹中的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!