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;
masta
  • 69
  • 1
  • 13
  • 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 03 '14 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. – Dmitry Streblechenko Nov 17 '14 at 05:51
  • Yeah but this is how i did it for now. Do you have any advise how to get AdressEntry better? – masta Nov 17 '14 at 07:17

1 Answers1

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)?

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • 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 03 '14 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? – Dmitry Streblechenko Oct 03 '14 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 '14 at 20:24