B
Barkster
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._MailItem).SaveAs(@"c:\testmsg.msg",
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");
}
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._MailItem).SaveAs(@"c:\testmsg.msg",
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");
}