简体   繁体   English

创建邮件发件人对象

[英]Create Mail Sender Object

I am creating an Email Object in Outlook 2013, but I cannot find how to create the Sender object. 我在Outlook 2013中创建了一个电子邮件对象,但我找不到如何创建Sender对象。 I am using this code: 我正在使用此代码:

Outlook.MailItem mail = (Outlook.MailItem)
         Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = "mail@gmail.com"
mail.Sender = // What goes here?
mail.Subject = "Mail subject";

The Sender object is an implementation of the Outlook.AddressEntry interface, so there must be an implementation somewhere, but where? Sender对象是Outlook.AddressEntry接口的实现,因此必须在某处实现,但在哪里? Is it possible to create this Sender object? 是否可以创建此Sender对象?

BTW, the sender of the email is not necessary an account registered in Outlook, so I cannot use the mail.SendUsingAccount property for that. 顺便说一句,电子邮件的发件人不一定是在Outlook中注册的帐户,所以我不能使用mail.SendUsingAccount属性。

Thanks to Dmitry Streblechenko on his comments above I could get the answer, and these are the lines to create an AddressEntry and assign it to a Sender : 感谢Dmitry Streblechenko上面的评论,我可以得到答案,这些是创建AddressEntry并将其分配给Sender

Outlook.MailItem mail = (Outlook.MailItem) Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipient recipient = Globals.ThisAddIn.Application.Session.CreateRecipient("mymail@domain.com");
mail.Sender = recipient.AddressEntry;

You cannot set this property Outlook.MailItem.Sender directly. 您不能直接设置此属性Outlook.MailItem.Sender

Only in cases where there are multiple account configured in the Outlook client, you can set this property to the AddressEntry object of the user that is represented by the CurrentUser property of a specific account. 仅在Outlook客户端中配置了多个帐户的情况下,您可以将此属性设置为由特定帐户的CurrentUser属性表示的用户的AddressEntry对象。

More Info: See http://msdn.microsoft.com/en-us/library/office/ff869056.aspx 更多信息:请参阅http://msdn.microsoft.com/en-us/library/office/ff869056.aspx

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM