1
votes

I have a code that checks the recipient of the mail, looks what organization is set in the address book for the recipient and dependent on that sets the "SentOnBehalfOfName"-property of the item. If the recipient is working for client2, he will get the mail from "[email protected]".

I call the code either before sending the mail via a button in my ribbon, that calls this Sub:

Sub Signatur()
Dim olApp As Outlook.Application
 Dim objMail As Outlook.MailItem
 Set olApp = Outlook.Application
 Set objMail = Application.ActiveInspector.CurrentItem
Call Signatur_auto(objMail)
End Sub

I do this if I want to know which mail-adress is going to be chosen.

In the itemSend-section of thisOutlookSession I also call the same sub

Call Signatur_auto(Item)

Part of the Signatur_auto (i do not copy that in, the question is too long already...) is dealing with the SentOnBehalfOfName-property, the other part is putting the item into the right folder. The Folder is chosen depending on the SentOnBehalfOfName-property.

Now comes the interesting part: Although the folder-part is always working (which can only be when the SentOnBehalfOfName has worked before), the SentOnBehalfOfName only works "half". In the preview-line the mail sent is shown as from "[email protected]", but when I open the mail it says it was sent by me. The Client always only sees my address, and also answers to my address - which I do not want....

How cant be, that the same code is having different results dependent on where it is called? Is it a Problem to change the sendonbehalf-field in the item send-section?

Thanks for any Inputs! Max

1

1 Answers

2
votes

Why it does not work?

Try this in ItemSend.

Dim copiedItem As mailItem

Set copiedItem = Item.Copy
copiedItem.SentOnBehalfOfName = "[email protected]"
copiedItem.Send    
Item.delete
Cancel = True ' In case your setup generates an error message as described in the comments

Why it works? Appears "copiedItem.Send" bypasses ItemSend.