1

i'm stack with Outlook issue where i want to change Email Sender. I want to send all emails from Outlook with one sender. When i change sender from Outlook it works fine but when i change it from Outlook plugin it's not work. I'm using following code:

private void adxOutlookEvents_ItemSend(object sender, ADXOlItemSendEventArgs e)
{
    if (e.Item is MailItem)  
    {  
        MailItem mail = e.Item as MailItem;  
        mail.SentOnBehalfOfName = "UserName";  
        mail.Save();  
        return; 
    } 
}

But nothing happens. I don't see any error or exception but email come to Outlook with old sender. Can you please help me with that?

UPDATED: The way how i fix it. We cant use property "SentOnBehalfOfName" Outlook handle it incorect. Except it you should use "Sender" property:

mail.Recipients.Add(mail.SentOnBehalfOfName);
mail.Recipients.ResolveAll();
var adressEntry = mail.Recipients[mail.Recipients.Count].AddressEntry;
mail.Recipients.Remove(mail.Recipients.Count);
mail.Sender = adressEntry;
3
  • Please be aware that outlook is not displaying the change of the sender, but does use it - very annoying. Have you tried sending?
    – Max
    Oct 3, 2014 at 16:55
  • 1
    There is absolutely no reason to add the temporary recipient - use Namespace.CreateRecipient, call Recipient.Resolve, then use its AddressEntry property. Nov 17, 2014 at 5:51
  • Yeah but this is how i did it for now. Do you have any advise how to get AdressEntry better?
    – masta
    Nov 17, 2014 at 7:17

1 Answer 1

1

Are you sending through Exchange and want to send on behalf of another user (do you have the permission?) or trying to send through a particular POP3/SMTP account (use MailItem.SendUsingAccount property)?

3
  • Yes i have rights for that i can change SendOnBefalf from Outlook. I'm sending email from Outlook and use Addin Express plugin for handle the events. How can i use SendUsingAccount? Can i change it from code how i can create this object for user email example@develop.local?
    – masta
    Oct 3, 2014 at 14:08
  • 1
    So what happens when you set SentOnBehalfOfName? What do you see in OutlookSpy (click IMessage) for the PR_SENDER_xyz and PR_SENT_REPRESENTING_xyz properties? Oct 3, 2014 at 15:18
  • thank you for help i checked PR_SENDER and PR_SENT_REPRESENTING properties with OutlookSpy and discovered that Outlook API for set SentOnBehalfName work incorect. But i found a wokreround how i can change SentObBehalfName. I can do if by setting Sender property. If somebody interesting on it you can see my code example in original post
    – masta
    Nov 16, 2014 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.