Outlook中的VBA脚本不适用于内部电子邮件 [英] vba script in outlook not working for internal emails
问题描述
所以我试图让一个脚本在每个发送到特定内部邮箱的项目上运行,而我在网上找到了此代码;
so I'm trying to get a script to run on every sent item to a specific internal mailbox and I found this code online;
Public Sub application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'check for address
If InStr(LCase(Item.To), "relevant.email@outlook.com") Then
'ask if we've added the date
prompt$ = "You're sending this to " & Item.To & ". have you added the due date?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
End Sub
所以该脚本仅适用于外部电子邮件(我一直在使用我的个人电子邮件进行测试),但不适用于内部邮箱,当您将其发送到内部邮箱时,该脚本甚至无法运行.
so the script works but solely for external emails (I've been using my personal email to test) but not for the internal mailbox, when you send it to the internal mailbox the script doesn't even run.
这似乎比其他问题更像是一个许可问题,但是我想看看你们中的任何一个是否有可能陷入困境.我不确定这是否是比看起来更常见的问题,但我一直无法可以在网上找到任何东西,而我在一夜之间只能做很多挠头工作!
this seems more like a persmissions issue than anything else but I wanted to see if any of you guys could possibly chip in. I wasn't sure if this was more of a common problem than it would appear but I have been unable to find anything online and there's only so much head scratching I can do in a night!
希望您能为您提供帮助.:)
hopefully you can help. :)
谢谢
汤姆.
推荐答案
To
属性只是使用;"连接的所有收件人"收件人的显示名称.它可能包含也可能不包含SMTP地址.
To
property is just the display name of all To recipients concatenated using ";". It may or may not contain the SMTP address.
遍历收件人"集合中的所有收件人,读取 Recipient.Type
属性以确保它是 olTo
.检索 Recipient.AddressEntry
属性(返回AddressEntry对象).如果 AddressEntry.Type ="SMTP"
,请使用 AddressEntry.Address
.如果 AddressEntry.Type ="EX"
,请使用 AddressEntry.GetExchangeUser.PrimarySmtpAddress
.
Loop through all recipients in the Recipients collection, read the Recipient.Type
property to make sure it is olTo
. Retrieve the Recipient.AddressEntry
property (returns AddressEntry object). If AddressEntry.Type = "SMTP"
, use AddressEntry.Address
. If AddressEntry.Type = "EX"
, use AddressEntry.GetExchangeUser.PrimarySmtpAddress
.
还请记住,必须将Cancel参数声明为 ByRef
.
Also keep in mind that the Cancel parameter must be declared as ByRef
.
dim addrType
dim addr
dim recip
for each recip in item.Recipients
if recip.Type = olTo Then
addrType = recip.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3002001F")
if addrType = "EX" Then
addr = recip.AddressEntry.GetExchangeUser.PrimarySmtpAddress
Else
addr = recip.Address
End If
if LCase(addr) = "relevant.email@outlook.com" Then
MsgBox "got it"
Exit for
End If
End If
next
这篇关于Outlook中的VBA脚本不适用于内部电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!