Hi Diane,
I had decided to solve this problem in a different way as there is no reason to waste your time with something, most probably server level anyway. I will merge the 2 exchange mailbox to one, than it will be a standard shared account, so that way, I will be able to access like the other ones. LOL! Its a solution anyway...
I had started to fix an other 2 problems (related to each other) I suffered a lot in outlook (apologize in advance for being long, but i wanted to be detailed so, you can understand the problems):
1. When I reply to someone, either reply, reply all, or forward, i would like to set the FROM sender based on the email recipient address I am replying on.
- So eg.: if I am replying on an email which were sent to:
test1@test.com;
moore@test.com, then I going through the recipients, find my address which is:
moore@test.com, open the message for reply, reply all, forward and set the From sender to
moore@test.com .
- Important to say, that
moore@test.com is properly in GAL address book and has full permission to send email on behalf, as I am using this on daily basis, just manually selected at Outlook From field. This is what I would like to automate. Also important to say, that I do NOT want to edit/modify the received email To/From header.
2. When I ReplyAll to someone, I want to remove my own email addresses (
moore@test.com,
moore@test2.com) from the TO/CC recipient fields of the cretated replyall message, I do NOT want to edit/modify the received email To/From header.
After i had searched through your superior articles and posts, I had found tons of reading and examples, so I was almost sure I can code this. But somehow, I ran into problem again.
Allow me to explain it in detail, for first, the code I had puzzled together (all added to ThisOutlookSession):
Code:
-------------------------------------------------------------------------------------
Dim WithEvents objOpenMail As Outlook.mailItem
Dim WithEvents objAppInspectors As Outlook.Inspectors
Dim WithEvents objMailInspector As Outlook.Inspector
Dim objResponse As mailItem
Private bDiscardEvents As Boolean
Private WithEvents objExplorer As Explorer
Private WithEvents objItem As Outlook.mailItem
Private Sub Application_Startup()
Set objAppInspectors = Application.Inspectors
Set objExplorer = Application.ActiveExplorer
bDiscardEvents = False
Ens Sub
-------------------------------------------------------------------------------------
Private Sub objAppInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class <> olMail Then
Exit Sub
End If
Set objOpenMail = Inspector.CurrentItem
Set objMailInspector = Inspector
End Sub
-------------------------------------------------------------------------------------
Private Sub objOpenMail_Open(Cancel As Boolean)
''''''''''' If I put it here, the code below, when only REPLY (and not REPLY ALL) it removes the originally sender from the new created reply email '''''
' Dim i As Integer
' Dim delitems As Integer
'
' On Error Resume Next
'
' delitems = 0
'
' For i = 1 To objOpenMail.Recipients.Count
'
' If objOpenMail.Recipients.Item(i).Name = "moore@test.com" Or "moore@test2.com" Then
'
' delitems = i
'
' End If
'
' Next
'
' If delitems <> 0 Then
'
' objOpenMail.Recipients.Remove (delitems)
'
' End If
End Sub
-------------------------------------------------------------------------------------
Private Sub objOpenMail_Close(Cancel As Boolean)
On Error Resume Next
Set objOpenMail = Nothing
End Sub
-------------------------------------------------------------------------------------
Private Sub objExplorer_SelectionChange()
On Error Resume Next
Set objItem = objExplorer.Selection.Item(1)
End Sub
-------------------------------------------------------------------------------------
Private Sub objItem_Reply(ByVal Response As Object, Cancel As Boolean)
On Error Resume Next
Cancel = True
bDiscardEvents = True
Set objResponse = objItem.Reply
ReplyForwardReplyAll
End Sub
-------------------------------------------------------------------------------------
Private Sub objItem_Forward(ByVal Response As Object, Cancel As Boolean)
On Error Resume Next
Cancel = True
bDiscardEvents = True
Set objResponse = objItem.Forward
ReplyForwardReplyAll
End Sub
-------------------------------------------------------------------------------------
Private Sub objItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
''''''''''''''' If I put this code here below instead of openMail it removes TO reciepient form oiriginal email '''''''''
' Dim i As Integer
' Dim delitems As Integer
'
' On Error Resume Next
'
' delitems = 0
'
' For i = 1 To objItem.Recipients.Count
'
' If objItem.Recipients.Item(i).Name = "moore@test.com" Or "moore@test2.com" Then
'
' delitems = i
'
' End If
'
' Next
'
' If delitems <> 0 Then
'
' objItem.Recipients.Remove (delitems)
'
' End If
Cancel = True
bDiscardEvents = True
Set objResponse = objItem.ReplyAll
ReplyForwardReplyAll
End Sub
-------------------------------------------------------------------------------------
Private Sub ReplyForwardReplyAll()
On Error Resume Next
'''''''''''''' How can i read original received message recipient '''''''''''''
For i = 1 To objItem.Recipients.Count
If objItem.Recipients.Item(i).Name = "moore@test.com" Then
objResponse.SentOnBehalfOfName = "moore@test.com"
End If
If objItem.Recipients.Item(i).Name = "moore@test2.com" Then
objResponse.SentOnBehalfOfName = "moore@test2.com"
End If
Next
objResponse.Display
End Sub
-------------------------------------------------------------------------------------
Its sort of work, BUT not in a correct way. There are basically 2 problems I ran into
PROBLEM ONE (removing original recipient):
- This is the code I use to remove my own email address when REPLY ALL:
Code:
Dim i As Integer
Dim delitems As Integer
On Error Resume Next
delitems = 0
For i = 1 To objOpenMail.Recipients.Count
If objOpenMail.Recipients.Item(i).Name = "moore@test.com" Or "moore@test2.com" Then
delitems = i
End If
Next
If delitems <> 0 Then
objOpenMail.Recipients.Remove (delitems)
End If
- The problem is, as you can see commented in my long code above, that i tried to add it into 2 different section. But if
A) I put it into objOpenMail_Open section, than when I simple reply to a person, it removes the person original sender email address from the newly created/opened Reply message window To field.
OR
B) If I put it into objItem_ReplyAll, than when I replyall to a person, it removes the person email address from the original received email header:
PROBLEM TWO (from sender originated from arrived email To recipient):
- After each Reply,replyall and forward, I call ReplyForwardReplyAll() to add one of my email address as From sender at the newly created/opened Reply/ReplyALl/Forward message window From field.
Code:
On Error Resume Next
For i = 1 To objItem.Recipients.Count
If objItem.Recipients.Item(i).Name = "moore@test.com" Then
objResponse.SentOnBehalfOfName = "moore@test.com"
End If
If objItem.Recipients.Item(i).Name = "moore@test2.com" Then
objResponse.SentOnBehalfOfName = "moore@test2.com"
End If
Next
objResponse.Display
- the problem is, that though I am trying to use objItem.Recipients, which should be the last selected message (so the original received message I m replying on), it isn't, therefore
the original TO email in the arrived email header cannot be found, therefore I cannot set to which of my email address the From field should be set, originated from the arrived email to address.
- This was the same according to debug when i tried to add code to either in objOpenMail or in objItem_Reply / Replyall / Forward.
I hope you still with me, and not get mad on me for this such a long message, and I hope I was able to explain, where I stuck.
Could you help me please? Because i couldn't figure it out myself, what am i doing wrong here, though I spent hours on it.
BIG BIG BIG thank you for your patience and help,
Moore