create new inbox folder and save emails
Posted
by kasunmit
on Stack Overflow
See other posts from Stack Overflow
or by kasunmit
Published on 2010-06-11T17:26:22Z
Indexed on
2010/06/11
17:32 UTC
Read the original article
Hit count: 364
c#3.0
i am trying http://www.c-sharpcorner.com/uploadfile/rambab/outlookintegration10282006032802am/outlookintegration.aspx[^] this code for create inbox personal folder and save same mails at the datagrid view (outlook 2007 and vsto 2008) i am able to create inbox folder according to above example but couldn't wire code for save e-mails at that example to save contect they r using following code
if (chkVerify.Checked)
{
OutLook._Application outlookObj = new OutLook.Application();
MyContact cntact = new MyContact();
cntact.CustomProperty = txtProp1.Text.Trim().ToString();
//CREATING CONTACT ITEM OBJECT AND FINDING THE CONTACT ITEM
OutLook.ContactItem newContact = (OutLook.ContactItem)FindContactItem(cntact, CustomFolder);
//THE VALUES WE CAN GET FROM WEB SERVICES OR DATA BASE OR CLASS. WE HAVE TO ASSIGN THE VALUES
//TO OUTLOOK CONTACT ITEM OBJECT .
if (newContact != null)
{
newContact.FirstName = txtFirstName.Text.Trim().ToString();
newContact.LastName = txtLastName.Text.Trim().ToString();
newContact.Email1Address = txtEmail.Text.Trim().ToString();
newContact.Business2TelephoneNumber = txtPhone.Text.Trim().ToString();
newContact.BusinessAddress = txtAddress.Text.Trim().ToString();
if (chkAdd.Checked)
{
//HERE WE CAN CREATE OUR OWN CUSTOM PROPERTY TO IDENTIFY OUR APPLICATION.
if(string.IsNullOrEmpty(txtProp1.Text.Trim().ToString()))
{
MessageBox.Show("please add value to Your Custom Property");
return;
}
newContact.UserProperties.Add("myPetName", OutLook.OlUserPropertyType.olText, true, OutLook.OlUserPropertyType.olText);
newContact.UserProperties["myPetName"].Value = txtProp1.Text.Trim().ToString();
}
newContact.Save();
this.Close();
}
else
{
//IF THE CONTACT DOES NOT EXIST WITH SAME CUSTOM PROPERTY CREATES THE CONTACT.
newContact = (OutLook.ContactItem)CustomFolder.Items.Add(OutLook.OlItemType.olContactItem);
newContact.FirstName = txtFirstName.Text.Trim().ToString();
newContact.LastName = txtLastName.Text.Trim().ToString();
newContact.Email1Address = txtEmail.Text.Trim().ToString();
newContact.Business2TelephoneNumber = txtPhone.Text.Trim().ToString();
newContact.BusinessAddress = txtAddress.Text.Trim().ToString();
if (chkAdd.Checked)
{
//HERE WE CAN CREATE OUR OWN CUSTOM PROPERTY TO IDENTIFY OUR APPLICATION.
if (string.IsNullOrEmpty(txtProp1.Text.Trim().ToString()))
{
MessageBox.Show("please add value to Your Custom Property");
return;
}
newContact.UserProperties.Add("myPetName", OutLook.OlUserPropertyType.olText, true, OutLook.OlUserPropertyType.olText);
newContact.UserProperties["myPetName"].Value = txtProp1.Text.Trim().ToString();
}
newContact.Save();
this.Close();
}
}
else
{
OutLook._Application outlookObj = new OutLook.Application();
OutLook.ContactItem newContact = (OutLook.ContactItem)CustomFolder.Items.Add(OutLook.OlItemType.olContactItem);
newContact.FirstName = txtFirstName.Text.Trim().ToString();
newContact.LastName = txtLastName.Text.Trim().ToString();
newContact.Email1Address = txtEmail.Text.Trim().ToString();
newContact.Business2TelephoneNumber = txtPhone.Text.Trim().ToString();
newContact.BusinessAddress = txtAddress.Text.Trim().ToString();
if (chkAdd.Checked)
{
//HERE WE CAN CREATE OUR OWN CUSTOM PROPERTY TO IDENTIFY OUR APPLICATION.
if (string.IsNullOrEmpty(txtProp1.Text.Trim().ToString()))
{
MessageBox.Show("please add value to Your Custom Property");
return;
}
newContact.UserProperties.Add("myPetName", OutLook.OlUserPropertyType.olText, true, OutLook.OlUserPropertyType.olText);
newContact.UserProperties["myPetName"].Value = txtProp1.Text.Trim().ToString();
}
newContact.Save();
this.Close();
}
}
else
{
//CREATES THE OUTLOOK CONTACT IN DEFAULT CONTACTS FOLDER.
OutLook._Application outlookObj = new OutLook.Application();
OutLook.MAPIFolder fldContacts = (OutLook.MAPIFolder)outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);
OutLook.ContactItem newContact = (OutLook.ContactItem)fldContacts.Items.Add(OutLook.OlItemType.olContactItem);
//THE VALUES WE CAN GET FROM WEB SERVICES OR DATA BASE OR CLASS. WE HAVE TO ASSIGN THE VALUES
//TO OUTLOOK CONTACT ITEM OBJECT .
newContact.FirstName = txtFirstName.Text.Trim().ToString();
newContact.LastName = txtLastName.Text.Trim().ToString();
newContact.Email1Address = txtEmail.Text.Trim().ToString();
newContact.Business2TelephoneNumber = txtPhone.Text.Trim().ToString();
newContact.BusinessAddress = txtAddress.Text.Trim().ToString();
newContact.Save();
this.Close();
}
}
///
/// ENABLING AND DISABLING THE CUSTOM FOLDER AND PROPERY OPTIONS.
///
///
///
private void rdoCustom_CheckedChanged(object sender, EventArgs e)
{
if (rdoCustom.Checked)
{
txFolder.Enabled = true;
chkAdd.Enabled = true;
chkVerify.Enabled = true;
txtProp1.Enabled = true;
}
else
{
txFolder.Enabled = false;
chkAdd.Enabled = false;
chkVerify.Enabled = false;
txtProp1.Enabled = false;
}
}
i don t have idea to convert it to save e-mails in the datagrid view
the data gride view i am mentioning here is containing details (sender address, subject etc.) of unread mails and the i i am did was perform some filter for that mails as follows
string senderMailAddress = txtMailAddress.Text.ToLower();
List list = (List)dgvUnreadMails.DataSource;
List myUnreadMailList;
List filteredList = (List)(from ci in list
where ci.SenderAddress.StartsWith(senderMailAddress)
select ci).ToList();
dgvUnreadMails.DataSource = filteredList;
it was done successfully then i need to save those filtered e-mails to that personal inbox folder i created already
for that pls give me some help my issue is that how can i assign outlook object just like they assign it to contacts (name, address, e-mail etc.) because in the e-mails we couldn't find it ..
© Stack Overflow or respective owner