{"id":66773,"date":"2006-08-02T15:02:00","date_gmt":"2006-08-02T15:02:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/08\/02\/how-can-i-get-a-list-of-all-the-senders-email-addresses-in-an-outlook-folder\/"},"modified":"2006-08-02T15:02:00","modified_gmt":"2006-08-02T15:02:00","slug":"how-can-i-get-a-list-of-all-the-senders-email-addresses-in-an-outlook-folder","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-a-list-of-all-the-senders-email-addresses-in-an-outlook-folder\/","title":{"rendered":"How Can I Get a List of All the Senders\u2019 Email Addresses in an Outlook Folder?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I get a list of all the senders\u2019 email addresses in an Outlook folder?<BR><BR>&#8212; CW<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, CW. You know, you must get email from a whole different set of people than we Scripting Guys do. For example, in looking through the Scripting Guys Inboxes it appears as though all our mail comes from the following sources:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Service representatives pointing out that our bank\/eBay\/PayPal account is about to expire, and noting that we need to log on to a specified Web site in order to prevent any interruption in service.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Evangelist Frank Radebe, the first son of the late Dr. John Radebe; Mr. Greg Stevenson, staff of Kleinwort Benson; Rev. Jones De; and Ms. Angela Dikko Emile, the daughter of Professor Emile Boga Doudou, all of whom need our help transferring money from an African bank to a U.S. bank. (But not as a favor to them, mind you; they\u2019re more than willing to pay us for our trouble.)<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Pharmaceutical salespeople who might be sampling their wares more than doctors recommend: \u201cTts h&#8217;erbal solution what hasnt no side effect, but has 100% guaranted resultss.\u201d<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Beautiful, sexy girls who got our names from a mutual friend and are just <I>dying<\/I> to meet the male Scripting Guys.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<TABLE id=\"EID\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Note<\/B>. OK, those last ones could be legitimate.<\/P>\n<P>Well, they <I>could<\/I> be.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>In other words, we Scripting Guys don\u2019t have much need to get a list of all the people who send <I>us<\/I> email. (OK, that h\u2019erbal solution might come in handy, but other than that \u2026) Like we said, though, you might hang around with a different crowd than we do. If that\u2019s the case, then a script like this one might be just the thing you need:<\/P><PRE class=\"codeSample\">Const olFolderInbox = 6<\/p>\n<p>Set objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)\nSet objFolder = objNamespace.GetDefaultFolder(olFolderInbox)<\/p>\n<p>Set colItems = objFolder.Items<\/p>\n<p>For Each objItem in colItems\n    Wscript.Echo objItem.SenderEmailAddress\nNext\n<\/PRE>\n<P>Yes, it <I>is<\/I> a nice little script, isn\u2019t it? (We\u2019re guessing that\u2019s why Angela Dikko Emile came to us for help; she probably figured that if we could write a script like that then transferring money from an African bank to a U.S. bank would be a snap.) As you can see, we start out simply enough, defining a constant named olFolderInbox and setting the value to 6; in a minute or two we\u2019ll use that constant to tell the script which Outlook folder we want to work with.<\/P>\n<P>After defining the constant we create an instance of the <B>Outlook.Application<\/B> object, then use the <B>GetNamespace<\/B> method to bind to the MAPI namespace. (That\u2019s actually the <I>only<\/I> namespace we can bind to, but we still have to bind to it. Kind of like having to fill out an income tax return even though they\u2019ve already taken all your money.) After that we use the <B>GetDefaultFolder<\/B> method to bind us to the Inbox folder:<\/P><PRE class=\"codeSample\">Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)\n<\/PRE>\n<P>See: we <I>told<\/I> you we\u2019d use the constant olFolderInbox to help us connect to the Inbox, didn\u2019t we?<\/P>\n<P>After connecting to the Inbox folder we can then use this line of code to retrieve a collection of all the items (i.e., all the email messages) found in that folder:<\/P><PRE class=\"codeSample\">Set colItems = objFolder.Items\n<\/PRE>\n<P>At this point all we have to do is set up a For Each loop and loop through the collection of email messages; for each message in that collection we simply echo back the value of the <B>SenderEmailAddress<\/B> property. Keep in mind, however, that when you try to access the SenderEmailAddress the following Outlook security dialog box is going to pop up onscreen:<\/P><IMG border=\"0\" alt=\"Outlook\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/office\/tips\/outlookbox.jpg\" width=\"359\" height=\"193\"> \n<P><BR>You\u2019ll need to select the <B>Allow access for<\/B> check box, pick a time period, and then click <B>Yes<\/B> before the script will be allowed to retrieve anyone\u2019s email address. (Yes, it\u2019s a bit of a hassle. However, it does help prevent you from doing things like inadvertently notifying all the people who have sent you email that their PayPal account is about to expire.)<\/P>\n<P>And that\u2019s it: in a matter of seconds the sender email addresses for all the items in your Inbox will be displayed onscreen.<\/P>\n<P>Like we said, this script retrieves information from your Inbox folders. What if you\u2019d like to pull the list of email addresses from a <I>subfolder<\/I> of the Inbox? To tell you the truth, we weren\u2019t sure if we could do that at first. However, after just one application of the miracle h\u2019erbal solution (\u201c100% guaranted resultss!\u201d) we came up with this:<\/P><PRE class=\"codeSample\">Const olFolderInbox = 6<\/p>\n<p>Set objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)\nSet objFolder = objNamespace.GetDefaultFolder(olFolderInbox)<\/p>\n<p>Set objSubfolder = objFolder.Folders(&#8220;Test&#8221;)<\/p>\n<p>Set colItems = objSubFolder.Items<\/p>\n<p>For Each objItem in colItems\n    Wscript.Echo objItem.SenderEmailAddress\nNext\n<\/PRE>\n<P>In this script we bind to \u2013 and retrieve email addresses from \u2013 a subfolder of the Inbox, a subfolder named Test. How do we do that? Well, after binding to the Inbox we use this line of code to connect us to the Test subfolder:<\/P><PRE class=\"codeSample\">Set objSubfolder = objFolder.Folders(&#8220;Test&#8221;)\n<\/PRE>\n<P>All we have to do then is make sure we retrieve the collection of emails from this subfolder:<\/P><PRE class=\"codeSample\">Set colItems = objSubFolder.Items\n<\/PRE>\n<P>Good question: that works if the folder is a subfolder on the Inbox. But what if the folder we\u2019re interested in is on the same level as the Inbox? How the heck do we access a folder like <I>that<\/I>? Well, we\u2019ll tell you, but you\u2019ll have to wait until tomorrow\u2019s column.<\/P>\n<P>Unless, of course, it turns out that we really <I>did<\/I> win $5 million in the Euro lottery. <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/aug06\/hey0803.mspx\"><B>Tune in tomorrow<\/B><\/A> to find out.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I get a list of all the senders\u2019 email addresses in an Outlook folder?&#8212; CW Hey, CW. You know, you must get email from a whole different set of people than we Scripting Guys do. For example, in looking through the Scripting Guys Inboxes it appears as though all our [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[212,49,3,5],"class_list":["post-66773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-outlook","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I get a list of all the senders\u2019 email addresses in an Outlook folder?&#8212; CW Hey, CW. You know, you must get email from a whole different set of people than we Scripting Guys do. For example, in looking through the Scripting Guys Inboxes it appears as though all our [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=66773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/66773\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=66773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=66773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=66773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}