Outlook – check email address type

Outlook – check email address type

囚你心 发布于 2021-11-30 字数 473 浏览 759 回复 1 原文

I am trying to make a macro in Outlook that will scan the To: list for a certain text string, and spit out a message if all but one (or two, etc) addresses have it. Is there a simple way to do this?

Essentially, I am trying to write something that'll avoid being able to send a restricted message to a bunch of people with the string 'xyz' in the address, if one or more do not have it. AutoComplete makes this difficult, without checking through one-by-one.

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。



需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。


你的往事 2022-06-07 1 楼

This is possible using Outlook VBA.

You'd have to write an event hook for when the user sends an email. This is done using the Application_ItemSend(ByVal Item As Object, Cancel As Boolean) where Item is the item being sent (email or appointment), and cancel is a boolean you can set to stop the email from being sent.

In your code you would want to look at the recipients collection on the Item object to see who is going to be receiving the email.
For example:

Dim CurrRecip As Recipient
For Each CurrRecip in Item.Recipients
    If InStr(1, CurrRecip.Address , "your search text here" , vbCompareText ) Then
        debug.print "Message here..."
    End If
Next CurrRecip

Hopefully that helps...