创建邮件发件人对象 [英] Create Mail Sender Object
问题描述
我正在Outlook 2013中创建电子邮件对象,但找不到如何创建发件人对象.我正在使用此代码:
I am creating an Email Object in Outlook 2013, but I cannot find how to create the Sender object. 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";
Sender对象是Outlook.AddressEntry
接口的实现,因此必须在某处实现,但是在哪里?可以创建此发送者对象吗?
The Sender object is an implementation of the Outlook.AddressEntry
interface, so there must be an implementation somewhere, but where? Is it possible to create this Sender object?
顺便说一句,电子邮件的发件人不一定是在Outlook中注册的帐户,因此我不能为此使用mail.SendUsingAccount
属性.
BTW, the sender of the email is not necessary an account registered in Outlook, so I cannot use the mail.SendUsingAccount
property for that.
推荐答案
感谢 Dmitry Streblechenko 在上面的评论中,我得到了答案,以下是创建AddressEntry
的代码行:将其分配给Sender
:
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
:
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;
这篇关于创建邮件发件人对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!