通过用户登录在Outlook中显示未读电子邮件 [英] Display of unread emails in outlook through user login
问题描述
我无法做到这一点。请检查一下。
我正在寻找C#中的过程,我提供任何Outlook的电子邮件ID和密码,并显示Outlook中所有未读的电子邮件。
例如:
电子邮件ID:xyz@example.com
密码:xyzpassword
当我提供此电子邮件ID时,我需要来自该帐户的所有未读电子邮件xyz@abc.com
电子邮件ID:rts@example.com
密码:rtspassword
当我给这个电子邮件ID我需要来自该帐户的所有未读电子邮件rts@abc.com
这就是我正在尝试的:
我想在运行时提供Outlook电子邮件的用户名和密码,我想访问该电子邮件的未读邮件。这可以在我登录Outlook帐户时解决,但它应该能够根据用户ID和密码访问任何Outlook帐户。
此代码仅供读取来自outlook的第一封电子邮件,但未发送未读邮件,并且未在运行时获取用户ID和密码。
private void btnAccessEmail_Click(对象发送者,EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace(MAPI);
Microsoft .Office.Interop.Outlook.MAPIFolder myContacts = mapiNameSpace.GetDefaultFolder(Microsoft.Office.In terop.Outlook.OlDefaultFolders.olFolderContacts);
// login
mapiNameSpace.Logon(null,null,false,false);
mapiNameSpace.Logon(my emailid,my emailid password,Missing 。值, true);
Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
Console.WriteLine(Total:,myItems.Count);
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace .GetDefaultFolder(Microsoft.Office.In terop.Outlook.OlDefaultFolders.olFolderInbox);
Console.Write(myInbox.Name);
Microsoft.Office.Interop.Outlook.Items inboxItems = myInbox.Items;
Console.WriteLine(Total:,inboxItems。数量);
Microsoft.Office.Interop.Outlook.Explorer myexp = myInbox.GetExplorer(false);
mapiNameSpace.Logon(Profile,Missing.Value,false,true);
if(myInbox.Items.Count> 0)
{
Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
inboxItems = inboxItems.Restrict([UnRead] = true);
Console.WriteLine(Total Unread:,inboxItems.Count);
// Int32 cnt = 0;
//尝试
// {
// foreach(Microsoft.Office.Interop.Outlook .MailItem邮件项目)
// {
// Console.WriteLine(mail.Subject);
// cnt ++;
// if(mail.UnRead == true)
// {
//}
//}
//}
// catch
// {< br $>
//}
//Console.WriteLine(cnt);
//抓住主题
lblSubject.Text =((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items [1])。主题;
//抓住身体
txtBod y.Text =((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items [1])。正文;
//发件人姓名
lblSenderName.Text =((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items [1])。SenderName;
//发件人电子邮件
lblSenderEmail.Text =((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items [1])。SenderEmailAddress;
//创建日期
lblCreationdate.Text =((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items [1])。CreationTime.ToString();
}
其他
{
MessageBox.Show(您的收件箱中没有电子邮件。);
}
}
}
Im unable to make this. Could please check with this.
I'm looking for the process in C# where I give email id and password of any outlook and to display all unread emails from Outlook.
Example:
Email id : xyz@example.com
Password : xyzpassword
When I give this email id I need all unread email from that account xyz@abc.com
Email id : rts@example.com
Password : rtspassword
When I give this email id I need all unread email from that account rts@abc.com
This is what I'm trying:
I want to give username and password of the Outlook email at the runtime and I would like to access the unread mails of that emails. This works out when I login to my outlook account, but it should be able to access any account of Outlook based on user id and password.
This code is reading only the first email from outlook but not the unread mail and its not taking user id and password at the runtime.
private void btnAccessEmail_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass( );
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myContacts = mapiNameSpace.GetDefaultFolder(Microsoft.Office.In terop.Outlook.OlDefaultFolders.olFolderContacts);
//login
mapiNameSpace.Logon(null, null, false,false);
mapiNameSpace.Logon("my Emailid", "my emailid password", Missing.Value, true);
Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
Console.WriteLine("Total : ", myItems.Count);
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.In terop.Outlook.OlDefaultFolders.olFolderInbox);
Console.Write(myInbox.Name);
Microsoft.Office.Interop.Outlook.Items inboxItems = myInbox.Items;
Console.WriteLine("Total : ", inboxItems.Count);
Microsoft.Office.Interop.Outlook.Explorer myexp = myInbox.GetExplorer(false);
mapiNameSpace.Logon("Profile", Missing.Value, false, true);
if (myInbox.Items.Count > 0)
{
Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
inboxItems = inboxItems.Restrict("[UnRead] = true");
Console.WriteLine("Total Unread :", inboxItems.Count);
//Int32 cnt = 0;
//try
//{
// foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items)
// {
// Console.WriteLine(mail.Subject);
// cnt++;
// if (mail.UnRead == true)
// {
// }
// }
//}
//catch
//{
//}
//Console.WriteLine(cnt);
// Grab the Subject
lblSubject.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items[1]).Subject;
// Grab the Body
txtBody.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items[1]).Body;
// Sender Name
lblSenderName.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items[1]).SenderName;
// Sender Email
lblSenderEmail.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items[1]).SenderEmailAddress;
// Creation date
lblCreationdate.Text = ((Microsoft.Office.Interop.Outlook.MailItem)myInbo x.Items[1]).CreationTime.ToString();
}
else
{
MessageBox.Show("There are no emails in your Inbox.");
}
}
}
推荐答案
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myContacts = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
//login
mapiNameSpace.Logon(null, null, false, false);
mapiNameSpace.Logon("yourMailAddress", "password", Missing.Value, true);
Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
// Console.WriteLine("Total : ", myItems.Count);
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
// Console.Write(myInbox.Name);
Microsoft.Office.Interop.Outlook.Items inboxItems = myInbox.Items;
// Console.WriteLine("Total : ", inboxItems.Count);
Microsoft.Office.Interop.Outlook.Explorer myexp = myInbox.GetExplorer(false);
mapiNameSpace.Logon("Profile", Missing.Value, false, true);
if (myInbox.Items.Count > 0)
{
Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
inboxItems = inboxItems.Restrict("[UnRead] = true");
Console.WriteLine(string.Format("Total Unread message {0}:", inboxItems.Count));
int x=0;
foreach (Microsoft.Office.Interop.Outlook.MailItem item in inboxItems)
{
Console.WriteLine("{0} unread mail from your inbox", ++x);
Console.WriteLine(string.Format("from:- {0}", item.SenderName));
Console.WriteLine(string.Format("To:- {0}", item.ReceivedByName));
Console.WriteLine(string.Format("Subject:- {0}", item.Subject));
Console.WriteLine(string.Format("Message:- {0}", item.Body));
System.Threading.Thread.Sleep(1000);
}
Console.ReadKey();
快乐编码:) :) :)
happy coding :) :) :)
这篇关于通过用户登录在Outlook中显示未读电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!