A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Selected Email Information



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 2nd 08, 09:25 PM posted to microsoft.public.outlook.program_addins
Barkster
external usenet poster
 
Posts: 5
Default Selected Email Information

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
  #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");
}

  #3  
Old June 3rd 08, 03:15 PM posted to microsoft.public.outlook.program_addins
Barkster
external usenet poster
 
Posts: 5
Default Selected Email Information

Thanks Sue, great information. Do you have an example on how to get
recipients?

On Jun 2, 4:08 pm, "Sue Mosher [MVP-Outlook]"
wrote:
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 ...
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");
}


  #4  
Old June 3rd 08, 04:00 PM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Selected Email Information

It's nothing but simple iteration and concatenation. I don't write C# code, but this is a VB.NET example:

Dim rString as String = ""
Dim r as Outlook.Recipient
For Each r in item.Recipients
rString = rString & ";" & r.Address
Next
MessageBox.Show rString

--
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 ...
Thanks Sue, great information. Do you have an example on how to get
recipients?

On Jun 2, 4:08 pm, "Sue Mosher [MVP-Outlook]"
wrote:
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.



"Barkster" wrote in ...
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");
}


  #5  
Old June 3rd 08, 05:03 PM posted to microsoft.public.outlook.program_addins
Barkster
external usenet poster
 
Posts: 5
Default Selected Email Information

Thanks Sue, I'm not much of a programmer so this helped a bit. When I
was trying to access it I was getting object error. Thanks for all
the help!
  #6  
Old June 3rd 08, 05:20 PM posted to microsoft.public.outlook.program_addins
Barkster
external usenet poster
 
Posts: 5
Default Selected Email Information

Hey Sue, my outlook is connected to an exchange server and when I get
the recipients, any internal recipient is show as "/o=CompanyName/
ou="domain"/cn=recipients/cn=username;" Do you know how I can get the
actual email address. Of course it get the email address of any
external emails but it would be nice to have email of internal
emails. Any help would be appreciated. Thanks
  #7  
Old June 3rd 08, 05:49 PM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Selected Email Information

That *is* an actual email address, in the X.400 format that Exchange uses. If you want the SMTP address for an Exchange sender or recipient in versions before Outlook 2007, you can use CDO or, to avoid security prompts, Redemption and the PR_EMAIL (&H39FE001E) MAPI property to obtain the SMTP address from the AddressEntry object. See http://www.outlookcode.com/d/code/ge...htm#redemption and http://www.cdolive.com/cdo5.htm#EMailAddressOfSender for examples. In ..NET languages, Microsoft doesn't officially support CDO and Extended MAPI. Redemption should work fine, and there are examples of using Extended MAPI, e.g. http://anoriginalidea.wordpress.com/...in-vbnet-vsto/.

See http://groups.google.com/group/micro...2fcbb691d5bf18 for a discussion of how to do it with Cached Exchange Mode in Outlook 2003 or later.
--
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 ...
Hey Sue, my outlook is connected to an exchange server and when I get
the recipients, any internal recipient is show as "/o=CompanyName/
ou="domain"/cn=recipients/cn=username;" Do you know how I can get the
actual email address. Of course it get the email address of any
external emails but it would be nice to have email of internal
emails. Any help would be appreciated. Thanks

  #8  
Old June 3rd 08, 07:25 PM posted to microsoft.public.outlook.program_addins
Barkster
external usenet poster
 
Posts: 5
Default Selected Email Information

Wow, thanks again for the great info. BTW, I ordered your book :-)
Thanks!
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
email selected contacts in groups Gary Hyatt Outlook Express 6 July 10th 07 08:10 PM
Email Selected or Not Macro Script [email protected] Outlook and VBA 4 May 4th 07 10:00 PM
sending selected email as attachment in new email draco Outlook and VBA 2 January 29th 07 01:20 PM
How could I retrieve free/busy information if the only information I have is the Email address? Wassim Dagash Add-ins for Outlook 1 January 18th 07 03:19 PM
my outlook email now comes in big text with normal 12 pt selected chasflies Outlook - Installation 1 January 30th 06 10:01 PM


All times are GMT +1. The time now is 08:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.