[英]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 时发生不安全中止......”
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.