
Thank you. I will try it.
I tried to rewrite my code as below
Case 1: If the mail is sent TO ******@f.com -> AutoForward To ******@x.com
Case 2: If the mail is sent TO ******@f.com ******@f.com ******@f.com -> AutoForward To ******@x.com ******@x.com
Could you please help me how to code in Case 2: If the mail is sent TO ******@f.com ******@f.com ******@f.com -> AutoForward To ******@x.com ******@x.com
Sub AutoForwardAllSentItems(Item As Outlook.MailItem)
Dim myFwd As Outlook.MailItem
Set myFwd = Item.Forward
Dim xStr1 As String
Dim xStr2 As String
Dim Recipient As String
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
'Case 1: If the mail is sent TO ******@x.com'
If recip = "******@x.com" Then
Recipient = "******@f.com"
xStr1 = "<p>A1</p>"
xStr2 = "<p>A2</p>"
'Case 2: If the mail is sent TO ******@x.com ******@x.com ******@x.com'
ElseIf recip = "******@x.com" "******@x.com" "******@x.com" Then
Recipient = "@f.com"
Recipient = "******@f.com"
Recipient = "******@f.com"
xStr1 = "<p>B1</p>"
xStr2 = "<p>B2</p>"
Else
MsgBox "None of the conditions was true, abort."
Exit Sub
End If
Next
myFwd.Recipients.Add Recipient
myFwd.HTMLBody = xStr1 & xStr2 & Item.HTMLBody
myFwd.Send
Set myFwd = Nothing