阅读outlook.com发送的电子邮件 [英] Read Email from outlook.com
问题描述
您好,
我有outlook.com的电子邮件帐户。如何从该帐户读取c#中的电子邮件。
I have email account of outlook.com. how to read email in c# from that account.
推荐答案
嗨Mahesh,
Hi Mahesh,
请参考以下项目:
安装Microsoft.Office.Interop.Outlook dll 首先,运行以下命令程序包管理器控制台中的命令:
Install Microsoft.Office.Interop.Outlook dll first, run the following command in the Package Manager Console:
安装包Microsoft.Office.Interop.Outlook -Version 15.0.4797.1003
Winform中的C#代码:
The C# code within Winform:
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
if (myInbox.Items.Count > 0)
{
// Grab the Subject
lblSubject.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).Subject;
//Grab the Attachment Name
if (((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).Attachments.Count > 0)
{
lblAttachmentName.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).Attachments[1].FileName;
}
else
{
lblAttachmentName.Text = "No Attachment";
}
// Grab the Body
txtBody.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).Body;
// Sender Name
lblSenderName.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).SenderName;
// Sender Email
lblSenderEmail.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).SenderEmailAddress;
// Creation date
lblCreationdate.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).CreationTime.ToString();
}
else
{
MessageBox.Show("There are no emails in your Inbox.");
}
}
如需更多信息,请参阅以下文件:
For more message please refer to the following document:
还有一些类似的链接可以帮助你:
Also there are some similar links may help you:
注意:此响应包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。 Microsoft不控制这些网站,也未测试在这些网站上找到的任何软件或信息;因此,
Microsoft不能就其中发现的任何软件或信息的质量,安全性或适用性做出任何陈述。使用互联网上的任何软件都存在固有的危险,微软提醒您在从互联网上检索任何软件之前,确保您完全了解风险。
Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
最好的问候,
Stanly
这篇关于阅读outlook.com发送的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!