我正在尝试通过自定义“发送”按钮的Application_ItemSend事件来使用C#创建Outlook外接程序。
在发送电子邮件之前,我需要所有电子邮件的详细信息。
当我运行下面的代码@ my home时,我通过将一些个人电子邮件id放入它的工作中得到了适当的结果。
但是当我在office outlook机器上运行这个类似的代码时,我得到了名字。
由于默认情况下,outlook的检查名称代码处于启用状态,因此它将返回名字和姓氏。
我正在使用Outlook 2010 @这两个地方。Office outlook映射到office active directory。我的家庭前景没有映射。谁能提供一个通用的解决方案,将给我所有的电子邮件地址使用(收件人,抄送,密件抄送和发件人),无论active directory映射或没有。
private void ThisAddIn_Startup(object sender, System.EventArgs e) {
Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
void Application_ItemSend(object Item, ref bool Cancel) {
Outlook.MailItem mail = Item as Outlook.MailItem;
Outlook.Inspector inspector = Item as Outlook.Inspector;
System.Windows.Forms.MessageBox.Show(mail.CC);
System.Windows.Forms.MessageBox.Show(mail.BCC);
} 发布于 2015-03-18 21:04:44
也许已经很晚了,但是有人可以检查这个代码(它对我来说很有效)
private string[] GetCCBCCFromEmail(Outlook.MailItem email)
{
string[] ccBCC = new string[] { "", "" };//cc y bcc
Outlook.Recipients recipients = email.Recipients;
foreach (Outlook.Recipient item in recipients)
{
switch (item.Type)
{
case (int)Outlook.OlMailRecipientType.olCC:
ccBCC[0] += GetEmail(item.AddressEntry) + ";";
break;
case (int)Outlook.OlMailRecipientType.olBCC:
ccBCC[1] += GetEmail(item.AddressEntry) + ";";
break;
}
}
return ccBCC;
}
private string GetEmail(Outlook.AddressEntry address)
{
string addressStr = "";
if (address.AddressEntryUserType ==
Outlook.OlAddressEntryUserType.
olExchangeUserAddressEntry
|| address.AddressEntryUserType ==
Outlook.OlAddressEntryUserType.
olExchangeRemoteUserAddressEntry)
{
//Use the ExchangeUser object PrimarySMTPAddress
Outlook.ExchangeUser exchUser =
address.GetExchangeUser();
if (exchUser != null)
{
addressStr = exchUser.PrimarySmtpAddress;
}
}
//Get the address from externals
if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.
olSmtpAddressEntry)
{
addressStr = address.Address;
}
return addressStr;
}希望能有所帮助
发布于 2014-10-31 21:38:07
To/CC/BCC属性(对应于MAPI中的PR_DISPLAY_ to /CC/BCC )由存储提供程序在保存项目时更新(MailItem.Save)。您还可以使用MailItem.Recipeints集合访问所有收件人。
https://stackoverflow.com/questions/26674312
复制相似问题