【问题标题】:Unable to access Outlook 2013 email sender address using c#无法使用 c# 访问 Outlook 2013 电子邮件发件人地址
【发布时间】:2020-11-26 23:56:46
【问题描述】:

我编写了一些 C# (VS2019) 代码来检测传入的 Outlook 电子邮件并将任何文件附件保存到给定位置。这工作正常,我现在添加了一个过滤器来检查源电子邮件地址,以便只处理来自给定发件人列表的电子邮件。

我的问题是,虽然这在我的笔记本电脑上运行良好,但当我尝试访问发件人的电子邮件地址时,它在服务器上静默失败。我的异常处理块没有捕获任何东西,程序也没有崩溃。

两台机器都运行 Outlook 2013。服务器运行 Win Server 2012,我的笔记本电脑是 Windows 10,64 位。

程序在服务器上作为计划的控制台应用程序任务在专用用户身份下运行。此身份是程序监控的 Outlook 帐户的所有者。

在我的机器上进行调试时,会出现一个弹出窗口,上面写着“为了防止在评估函数 System.Reflection.Assembly.Load from all threads are allowed to run 时发生不安全的中止......”

Popup is here

任何想法将不胜感激!这让我发疯...... :(

谢谢

安德鲁

代码如下(我已经编辑掉了不相关的东西,包括一个日志功能):

public class EvtNewMail : EventArgs
{
    public EvtNewMail(MailItem email);

    public MailItem email { get; }

    public override string ToString();
}



    private static void Listener_OnNewMail(object sender, EvtNewMail e)
    {
        try
        { 
                string theSender = string.empty; 
         
                string senderName = e.email.Sender.Name;  

                string emailType = e.email.SenderEmailType.ToUpper();

                if (emailType == "SMTP")
                {
                    Log("Email type SMTP");
                    **theSender = e.email.SenderEmailAddress;** ***//FAILS HERE***
                         **//         e.email.Sender.Address Also fails**
                }
                else if (emailType == "EX")
                {
                    Log("Email type EX");
                    theSender = e.email.Sender.GetExchangeUser().PrimarySmtpAddress;
                }               

        }
        catch (System.Exception ex)
        {
            Log(Environment.MachineName + ": Error handling mail message here '")
        }

    }

【问题讨论】:

    标签: c# email outlook


    【解决方案1】:

    什么是“MessagePriority”,它是如何定义的?如果它是命名空间的一部分,是哪一个?

    【讨论】:

    • 这只是我的日志功能的一个附带部分,与 Outlook 的东西无关。抱歉,应该把它删掉。
    猜你喜欢
    • 2016-02-19
    • 2014-10-16
    • 2012-06-24
    • 2021-03-08
    • 1970-01-01
    • 2011-03-13
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多