Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create an application send and receive as outlook by c#
example:
if it is the first, app will read all email, but if it is the second , app only read mail unread ???
Posted

BY using Microsoft.Office.Interop.Outlook;

you can Read/Write/Delete all the feature of outlook.


C#
private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Outlook.MAPIFolder deletedFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
           deletedFolder.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(DeletedItems_ItemAdd);

        }

        void DeletedItems_ItemAdd(object Item)
        {
            if (Item is Outlook.MailItem)
            {
                (Item as Outlook.MailItem).UnRead = false;
            }
            else if (Item is Outlook.AppointmentItem)
            {
                (Item as Outlook.AppointmentItem).UnRead = false;
            }
            else if (Item is Outlook.MeetingItem)
            {
                (Item as Outlook.MeetingItem).UnRead = false;
            }
            else if (Item is Outlook.ContactItem)
            {
                (Item as Outlook.ContactItem).UnRead = false;
            }
            else if (Item is Outlook.JournalItem)
            {
                (Item as Outlook.JournalItem).UnRead = false;
            }
            else if (Item is Outlook.TaskItem)
            {
                (Item as Outlook.TaskItem).UnRead = false;
            }
            else if (Item is Outlook.TaskRequestItem)
            {
                (Item as Outlook.TaskRequestItem).UnRead = false;
            }
            else if (Item is Outlook.PostItem)
            {
                (Item as Outlook.PostItem).UnRead = false;
            }
            else if (Item is Outlook.PostItem)
            {
                (Item as Outlook.PostItem).UnRead = false;
            }
        }
 
Share this answer
 
Comments
Tuấn Ngọc 30-Nov-12 2:59am    
can you give me a demo about it ? or posts talk about it ?
Raman Thakur 30-Nov-12 3:50am    
first of tell me whats your requirement. You want to send email from c# using smtp or you want to use existing outlook to send mail and read outlook?
Tuấn Ngọc 1-Dec-12 6:34am    
i want to use existing outlook to send mail and read outlook. the better if it have interface of outlook
Raman Thakur 5-Dec-12 6:11am    
add refrence of using Outlook.Microsoft.Office.Interop.Outlook;

the send like below:
Microsoft.Office.Interop.Outlook.Application olkApp1 =
new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem olkMail1 =
(MailItem)olkApp1.CreateItem(OlItemType.olMailItem);
olkMail1.To = txtpsnum.Text;
olkMail1.CC = "";
olkMail1.Subject = "Assignment note";
olkMail1.Body = "Assignment note";
olkMail1.Attachments.Add(AssignNoteFilePath,
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1,
"Assignment_note");
olkMail1.Save();
Raman Thakur 12-Dec-12 5:02am    
Microsoft.Office.Interop.Outlook.Application oApplication = new Microsoft.Office.Interop.Outlook.Application();
MailItem vMailItem = oApplication.CreateItem(OlItemType.olMailItem) as MailItem;
vMailItem.To = "Abc@xyz.com";
vMailItem.CC = "CCMailID@xyz.com";
vMailItem.Subject = "MeetingSubject";
vMailItem.Body = "MeetingBody";
vMailItem.Display(true);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900