简体   繁体   English

无法使用 c# 访问 Outlook 2013 email 发件人地址

[英]Unable to access Outlook 2013 email sender address using c#

I've written some C# (VS2019) code to detect incoming Outlook emails and save any file attachments to a given location.我编写了一些 C# (VS2019) 代码来检测传入的 Outlook 电子邮件并将任何文件附件保存到给定位置。 This works OK, and I now have added a filter to check the source email address so that only emails from a given list of senders are processed.这工作正常,我现在添加了一个过滤器来检查源 email 地址,以便只处理来自给定发件人列表的电子邮件。

My problem is that while this works fine on my laptop, it fails silently on the server when I try to access the email address of the sender.我的问题是,虽然这在我的笔记本电脑上运行良好,但当我尝试访问发件人的 email 地址时,它在服务器上静默失败。 My exception handling block doesn't catch anything, and the program does not crash out.我的异常处理块没有捕获任何东西,程序也没有崩溃。

Both machines are running Outlook 2013. The server is running Win Server 2012, and my laptop is Windows 10, 64 bit.两台机器都运行 Outlook 2013。服务器运行 Win Server 2012,我的笔记本电脑是 Windows 10、64 位。

The program runs on the server as a scheduled console app task under a dedicated user identity.该程序以专用用户身份作为计划的控制台应用程序任务在服务器上运行。 This identity is the owner of the Outlook account that the program monitors.此身份是程序监控的 Outlook 帐户的所有者。

When running in debug on my machine, a pop up appears with wording "To prevent an unsafe abort when evaluating the function System.Reflection.Assembly.Loadfrom all threads were allowed to run...."在我的机器上进行调试时,会出现一个弹出窗口,上面写着“为了防止在评估 function System.Reflection.Assembly.Load from all threads are allowed to run 时发生不安全中止......”

Popup is here弹出窗口在这里

Any thoughts would be gratefully received.任何想法将不胜感激。 This is driving me mad..: :(这让我发疯.. :(

Thanks谢谢

Andrew安德鲁

Code is as follows (I've edited out unrelated stuff, including a logging function):代码如下(我已经编辑了不相关的东西,包括一个日志功能):

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 '")
        }

    }

What is "MessagePriority" and how is it defined?什么是“MessagePriority”,它是如何定义的? If it's part of a namespace, which one?如果它是命名空间的一部分,是哪一个?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#中的Outlook对象发送电子邮件时更改发件人的电子邮件地址和名称 - Changing the Sender's email address and name when sending an email using an Outlook object in C# C# VSTO Outlook 插件 - 如何使用传出 Z0C83ZEFA57C7831CEB7B24 获取发送方的 email 地址? - C# VSTO Outlook plugin - How can I get the email address of the sender of an outgoing email using Exchange? 使用Outlook 2013和C#编写电子邮件 - Compose email using outlook 2013 with C# 如何使用 C# 放置电子邮件的发件人,我的 Outlook 应用程序中有 3 个电子邮件 - How to put the email's sender using C#, I have 3 email in my outlook application 使用C#在运行时访问Custom Outlook 2013功能区 - Access Custom outlook 2013 ribbon at runtime using c# 如何使用c#从具有MultiAccount的Outlook 2010中的“撰写邮件”窗口中的(发件人)邮件地址获取信息? - how to get from(sender) mail address in Compose mail window in outlook 2010 having MultiAccount using c#? C#通过电子邮件地址找到Outlook联系人 - c# find outlook contact by email address 通过c#获取Outlook电子邮件地址 - Get Outlook email address through c# 如何在C#中更改发件人电子邮件地址? - How can I change the Sender Email Address in C#? 打开多封邮件时获取发件人电子邮件地址c# - Get sender email address when multiple mails are opened c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM