Issue with SentOnBehalfOfName

2019-05-30 16:38发布

问题:

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;

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