View Single Post
  #2  
Old June 2nd 08, 10:08 PM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Selected Email Information

The Parent property of any Outlook item returns a MAPIFolder or, in OUtlook 2007, Folder object representing the folder it is stored in. Use the Namespace.GetDefaultFolder method to return the Inbox or Sent Items folder for your comparison.

To gather recipients into a string, iterate the Recipients collection and append each Recipient.Name or Recipient.Address (or both) as you desire to the string.

StoreID is a unique identifier for a data store -- Exchange mailbox, ..pst file, Exchange public folders hierarchy -- that, together with the EntryID value for an item or folder, allows you to return that item using the Namespace.GetItemFromID or Namespace.GetFolderFromID method.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Barkster" wrote in message ...
I trying to build a toolbar button that collects information about the
selected email then stores the information in a database. I'm able to
extract some of the information but I would like to determine if the
email selected is in the inbox, subfolder or in sent items. I cannot
figure out how to do this nor can I figure out how to gather the
recipients into a string. Here is what I have so far, any help would
be appreicated. Also, what is storeID?

try
{
sel = activeExplorer.Selection;
if (sel.Count 1)
{
MessageBox.Show("Please only select one email
at a time");
}
else
{
if (sel[1] is Outlook.MailItem)
{
try
{
// Generate the time stamp.
double timestamp =
ConvertToUnixTimestamp(DateTime.Now);

//need to somehow check of sent or
received
Outlook._MailItem item =
((object)sel[1] as Outlook._MailItem);

//instead of saving the file need to
pass it to the form
string from = item.SenderEmailAddress;
string subject = item.Subject;
string body = null;
DateTime received = item.ReceivedTime;

if (item.Body.Length 250)
{
body = item.Body.Substring(0,
250);
}
else
{
body = item.Body;
}

Form1 form1 = new Form1(ds1);
if (form1.ShowDialog() ==
DialogResult.OK)
{
//lookup to see if has already
been filed;

//save the file to network
try
{
//item.SaveAs(@"c:\" + username
+ "_" + timestamp.ToString() + ".msg", Outlook.OlSaveAsType.olMSG);
}
catch (Exception ex)
{
MessageBox.Show("Sorry we were
unable to file your email message, please try again");
}
//add information to database
try
{
string s =
form1.comboBox1.SelectedValue.ToString();
MessageBox.Show("Email from: "
+ from + System.Environment.NewLine + "Subject: " + subject +
System.Environment.NewLine + "has been successfully filed on the X:
Drive");
}
catch (Exception ex)
{
MessageBox.Show("Sorry we were
unable to file your email message, please try again");
}
}
else
{
MessageBox.Show("Email not
saved.");
}

//(selecteditem as
",
Outlook.OlSaveAsType.olMSG);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("The item you have
selected is not an email message");
}

}
}
catch (Exception ex)
{
MessageBox.Show("Exception" + ex.Message,
"Exception in button click event");
}

Ads