【发布时间】:2021-03-03 13:39:01
【问题描述】:
在我的 Outlook 插件中,我需要添加创建新电子邮件的条件。 .TO 字段中只能有一个收件人。
不允许将配方添加到字段.CC、BCC。
(inspectorMailItem.Recipients.Count != 1) 的条件有效,(inspectorMailItem.Attachments.Count == 0) 的条件也有效。
但是为什么不能为(inspectorMailItem.CC.Count != 0) 做同样的事情呢?
错误Operator '!=' cannot be applied to operands of type 'method group' and 'int'
Microsoft.Office.Interop.Outlook.Application application = new
Microsoft.Office.Interop.Outlook.Application();
Inspector inspector = application.ActiveInspector();
if (inspector.CurrentItem is MailItem inspectorMailItem)
{
String Subject = inspectorMailItem.Subject;
String EmailAddress = inspectorMailItem.To;
if (inspectorMailItem.Recipients.Count != 1)
{
MessageBox.Show("More then one recipient.");
}
else if (inspectorMailItem.CC.Count != 0)
{
MessageBox.Show("Recipient in CC not allowed.");
}
else if (inspectorMailItem.Bcc.Count != 0)
{
MessageBox.Show("Recipient in Bcc not allowed.");
}
else if (inspectorMailItem.Attachments.Count == 0)
{
MessageBox.Show("No attachment.");
}
else
{
//
}
更新
我将count 替换为length:
Microsoft.Office.Interop.Outlook.Application application = new
Microsoft.Office.Interop.Outlook.Application();
Inspector inspector = application.ActiveInspector();
if (inspector.CurrentItem is MailItem inspectorMailItem)
{
String Subject = inspectorMailItem.Subject;
String EmailAddress = inspectorMailItem.To;
if (inspectorMailItem.Recipients.Count != 1)
{
MessageBox.Show("More then one recipient.");
}
else if (inspectorMailItem.CC.Length != 0)
{
MessageBox.Show("Recipient in CC not allowed.");
}
else if (inspectorMailItem.Bcc.Length != 0)
{
MessageBox.Show("Recipient in Bcc not allowed.");
}
else if (inspectorMailItem.Attachments.Count == 0)
{
MessageBox.Show("No attachment.");
}
else
{
//
}
它可以工作,但是当.To 为空白且.CC 为空白时,只有BCC 填充有此错误:Object reference not set to an instance of an object.
详细问题是这一行
else if (inspectorMailItem.CC.Length != 0)
【问题讨论】:
标签: c# vsto outlook-addin mailitem