I have just one exchange account on outlook and access to two shared/group mailbox or mail address which are created by admin. I am just a member of that shared mail group and I can send and receive mails via them. So sometimes I make a mistake by choosing wrong sender address. I need to check sender/from address and recipients before sending emails. However, I can't return sender/from addresses as a string via VBA. I choose them by 'from' drop down menu.
Here is my code:
Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
Dim Send_Address As String
Dim checker As Integer
Send_Address = Item.SendUsingAccount.SmtpAddress
checker = 0
Set Recipients = Item.Recipients
For i = Recipients.Count To 1 Step -1
Set recip = Recipients.Item(i)
If InStr(LCase(recip.Address), "abc.com") Then
checker = 1
End If
If InStr(LCase(recip.Address), "xyz.com") Then
checker = 2
End If
Next i
If (Send_Address = "abc.om") And (checker = 1) Then
MsgBox ("Please check CC list. It includes different clients.")
Cancel = True
ElseIf (Send_Address = "xyz.com") And (checker = 2) Then
MsgBox ("Please check CC list. It includes different clients.")
Cancel = True
Else
MsgBox ("OK" & checker & Send_Address)
Cancel = True
End If
End Sub