Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29981

Outlook macro check sending email address before sending

$
0
0

I use multiple accounts in Outlook and therefore send from many different email addresses. I want to give a warning box if I am sending from an address I should not be sending from. I have two addresses that I should never send from (they are receive only accounts. I do not want to accidentally send from these accounts.

This example is almost what I am looking for. Example - Checking the "To" address.

I believe using a string comparison (StrComp) and Item.SenderEmailAddress is what I need. However I can't seem to get it to work.

Here is my current attempt for giving a warning for a single email address (bad.email@gmail.com).

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)On Error Resume Next' use lower case for the address' LCase converts all addresses in the To field to lower caseIf StrComp((Item.SenderEmailAddress), "bad.email@gmail.com") Then    Exit SubEnd If        Prompt$ = "You sending this from "& Item.SenderEmailAddress & ". Are you sure you want to send it?"       If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then         Cancel = True       End IfEnd Sub

Ideally I would be able to check two or more addresses with the same code. Using something like they did in that example should work.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)    On Error Resume Next   Select Case LCase(Item.To)    Case "alias@domain.com", "alias2@domain3.com", "alias3@domain3.com"        Item.Send    Case Else      Prompt$ = "You are not sending this to "& Item.To & ". Are you sure you want to send the Mail?"       If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then         Cancel = True       End If    End SelectEnd Sub

Also, where do I place the code to ensure that it is constantly running and ready?


Viewing all articles
Browse latest Browse all 29981

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>