【问题标题】:How to remove "on behalf of " while sending mail from C# using Microsoft.Office.Interop.Outlook如何在使用 Microsoft.Office.Interop.Outlook 从 C# 发送邮件时删除“代表”
【发布时间】:2020-09-24 01:30:42
【问题描述】:

这是共享邮箱,可以访问我的电子邮件以发送和接收邮件。但是,当我从共享邮箱通过 Outlook 发送邮件时,我没有收到“代表”消息,而当我从代码发送邮件时,我代表 sharedEmail.com 收到 MyEmail.com。

var app = new Application();
                MailItem mailItem = app.CreateItem(OlItemType.olMailItem);
                mailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;               
                var attachments = mailItem.Attachments;
                mailItem.Subject = item.Capability + " - " + appSettings["Subject"].ToString();
                mailItem.HTMLBody = CreateBody(appSettings);
                mailItem.CC= appSettings["CCEmails"].ToString();  
                mailItem.Recipients.Add(appSettings["FromAddress"]);
                mailItem.Recipients.ResolveAll();
                var adressEntry = mailItem.Recipients[mailItem.Recipients.Count].AddressEntry;
                mailItem.Recipients.Remove(mailItem.Recipients.Count);                                          
                mailItem.Sender = adressEntry;
                mailItem.To = item.EmailId;    
                mailItem.Importance = OlImportance.olImportanceHigh;
                mailItem.Send();
                ReleaseObj(app);

以下我已经尝试过的事情。

1.使用 SendUsingAccount - 这不起作用,因为邮件被配置为共享邮箱而不是共享帐户,因此该邮箱未在帐户下列出。

2.使用 SentOnBehalfOfName-这也不起作用,我按照堆栈溢出用户解决方法之一设置发件人名称。

3.许多答案都建议从管理员启用“发送为”或“代表”权限,但如果权限是问题,为什么我只能通过代码而不是通过 Outlook 收到“代表”消息客户。

提前感谢您的帮助

【问题讨论】:

    标签: c# email outlook automation


    【解决方案1】:

    你有:

    mailItem.Sender = adressEntry;
    

    但似乎缺少发件人地址,我没有尝试但添加这些行可能会覆盖“代表”:

    EmailAddress fromSender = new EmailAddress();
    fromSender.Address = _sharedOutlookMailAccount;
    message.From = fromSender;
    

    参考:How to send email via a Shared MailBox using Exchange Web Services (EWS) API

    【讨论】:

    • 感谢您的回答。如果可行,将尝试并更新组
    猜你喜欢
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 2011-01-08
    • 1970-01-01
    • 2011-01-22
    • 2012-02-07
    相关资源
    最近更新 更多