PDA

View Full Version : SentOnBehalfOfName doesn't work, in Outlook 2007 Macro.



jsfarum
04-30-2013, 01:59 AM
Hi,

I'm working on a macro that replies with a certain text to the sender and moves the message to a specific folder.
These messages are placed in a shared mailbox.
I can't get the SentOnBehalfOfName function to work, i dont get any error, but the message turns up with the shared mailbox owner as the mail sender.
It works, when answering manually, so the permitions is correctly setup.



Sub ReplyAndMove()
Dim oMail As MailItem
Dim oMail2 As MailItem
stext = "Here is the reply text"
If TypeOf Application.ActiveExplorer.Selection(1) Is Outlook.MailItem Then
Set objFolder = Application.GetNamespace("MAPI").Folders("Some mailbox").Folders("Some folder")

Set oMail2 = Application.ActiveExplorer.Selection(1)
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.BodyFormat = olFormatHTML
oMail.HTMLBody = stext & vbCr & oMail.HTMLBody
oMail.SentOnBehalfOfName = "user@domain.com"
oMail.Display
oMail.DeleteAfterSubmit = True 'Set to True if a copy of the mail message is not saved upon being sent
oMail.Send
Set oMail = Nothing
oMail2.Move objFolder
Set oMail2 = Nothing
Set objFolder = Nothing
End If
End Sub

Any suggestions, what the problem could be?

BR
Jasper