reubendayal
Senior Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Hi Diane,
Hope you are doing well.
I am trying to use your lovely code from slipstick.com's webpage - Warn Before Sending Messages to the Wrong Email Address
And need to customize it to display in the prompt the SMTP address of the receivers something that in your above webpage you are referring to under the "Check for different domains". I further need the code to display the SMTP address as some sensible text string for the user as some of the email address are simply too similar to one another and can cause confusion when the user is adding them on to the "To" address field of the email. For example: the email names (without the SMTP address are displayed as Mobility; HR Mobility; HR Internal; HR Support; HRServiceDesk. And this as you can see is quite confusing.
The idea is to have all these email addresses listed in one message box prompt as a list and then if the user clicks okay the email is sent and if the user hits cancel, the email remains unsent (so the user can go in to the email and correct the recipient/s).
And I found another code online but that seems to do the for loop for one email at a time from - How do you extract a recipient's smtp address from an email?
thank you for helping!
Reuben
Hope you are doing well.
I am trying to use your lovely code from slipstick.com's webpage - Warn Before Sending Messages to the Wrong Email Address
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
Dim pa As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
On Error Resume Next
' use lower case for the address
' LCase converts all addresses in the To field to lower case
Set Recipients = Response.Recipients
For i = Recipients.Count To 1 Step -1
Set recip = Recipients.Response(i)
Set pa = recip.PropertyAccessor
Debug.Print recip.Address
If InStr(LCase(recip.Address), "bad@domain.com") Then
prompt$ = "You are sending this email to: " & vbCrLf & vbCrLf & _
Response.To & "." & vbCrLf & vbCrLf & _
"Are you sure you want to send it?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
Exit For
End If
End If
Next i
End Sub
And need to customize it to display in the prompt the SMTP address of the receivers something that in your above webpage you are referring to under the "Check for different domains". I further need the code to display the SMTP address as some sensible text string for the user as some of the email address are simply too similar to one another and can cause confusion when the user is adding them on to the "To" address field of the email. For example: the email names (without the SMTP address are displayed as Mobility; HR Mobility; HR Internal; HR Support; HRServiceDesk. And this as you can see is quite confusing.
The idea is to have all these email addresses listed in one message box prompt as a list and then if the user clicks okay the email is sent and if the user hits cancel, the email remains unsent (so the user can go in to the email and correct the recipient/s).
And I found another code online but that seems to do the for loop for one email at a time from - How do you extract a recipient's smtp address from an email?
Code:
Sub GetSMTPAddressForRecipients(mail As Outlook.MailItem)
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = mail.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
Debug.Print recip.name & " SMTP=" _
& pa.GetProperty(PR_SMTP_ADDRESS)
Next
End Sub
thank you for helping!
Reuben