{"id":1007,"date":"2012-01-16T01:01:50","date_gmt":"2012-01-15T19:31:50","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=1007"},"modified":"2012-01-16T01:19:24","modified_gmt":"2012-01-15T19:49:24","slug":"automating-outlook-using-qtp-emails-in-outlook","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/","title":{"rendered":"Part 5: Automating Outlook using QTP | Emails in Outlook"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Verdana;\">\n<p>In this article, you would see how to access emails in outlook, how to send emails using outlook and how to access different properties of an email item. To access email items, you can use <strong>MailItem<\/strong> class which contains the methods and properties to work with email items.<!--more--> Let&#8217;s directly jump onto the examples &#8211;<br \/>\n<span><br \/>\n<\/span><br \/>\n<strong>Sample Code 1: Sending emails using Outlook.<\/strong> This topic has already been covered in a previous article. You can read <a title=\"How to send emails using QTP from Microsoft Outlook\" href=\"http:\/\/www.automationrepository.com\/2011\/11\/how-to-send-emails-using-qtp-from-microsoft-outlook\/\" target=\"_blank\">how to send emails using Outlook<\/a> (You can also read <a title=\"How to send emails using QTP from Gmail and Yahoo\" href=\"http:\/\/www.automationrepository.com\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/\" target=\"_blank\">how to send emails using GMail and Yahoo<\/a>).<br \/>\n<span><br \/>\n<\/span><br \/>\n<strong>Sample Code 2: Access different properties of a mail item.<\/strong> In this example, you&#8217;ll see how to access the mails in an outlook folder (eg. inbox folder) and find out various properties of a particular mail item.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim olFolderInbox, iTotalMails, sSubject\r\nolFolderInbox = 6 : sSubject = &quot;&quot;\r\n\r\nSet objOutlook = CreateObject(&quot;Outlook.Application&quot;)\r\nSet objNamespace = objOutlook.GetNamespace(&quot;MAPI&quot;)\r\n\r\n'Create reference to Inbox Folder\r\nSet oInbox = objNamespace.GetDefaultFolder(olFolderInbox)\r\n\r\n'Find all items in the Inbox Folder\r\nSet oAllMails = oInbox.Items\r\n\r\n'Find out properties of the mail item\r\nsSubject = sSubject &amp; &quot;To -&gt; &quot; &amp; oAllMails(1).To &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;CC -&gt; &quot; &amp; oAllMails(1).CC &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;BCC -&gt; &quot; &amp; oAllMails(1).BCC &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;Subject -&gt; &quot; &amp; oAllMails(1).Subject &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;Body -&gt; &quot; &amp; oAllMails(1).Body &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;Creation Time -&gt; &quot; &amp; oAllMails(1).CreationTime &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;Is Marked Important -&gt; &quot; &amp; oAllMails(1).Importance &amp; vbCrLf\r\nsSubject = sSubject &amp; &quot;Received at -&gt; &quot; &amp; oAllMails(1).ReceivedTime &amp; vbCrLf\r\n\r\n'Display the result\r\nmsgbox sSubject\r\n<\/pre>\n<div style=\"width: 290px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"Outlook Email Properties\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png\" alt=\"Outlook Email Properties\" width=\"280\" height=\"289\" \/><p class=\"wp-caption-text\">Outlook Email Properties<\/p><\/div>\n<p><span><br \/>\n<\/span><br \/>\n<strong>Sample Code 3: Find out the list of all unread emails in Outlook Inbox.<\/strong> This example loops through all the emails in Inbox folder and reports out the unread email items.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim olFolderInbox, iTotalMails, sSubject\r\nolFolderInbox = 6 : sSubject = &quot;&quot;\r\n\r\nSet objOutlook = CreateObject(&quot;Outlook.Application&quot;)\r\nSet objNamespace = objOutlook.GetNamespace(&quot;MAPI&quot;)\r\n\r\n'Create reference to Inbox Folder\r\nSet oInbox = objNamespace.GetDefaultFolder(olFolderInbox)\r\n\r\n'Find all items in the Inbox Folder\r\nSet oAllMails = oInbox.Items\r\niTotalMails = oAllMails.Count\r\n\r\n'Loop through the mail items\r\nFor i=1 to iTotalMails\r\n  'Check if the mail is UnRead or not\r\n  If oAllMails(i).UnRead = True Then\r\n     sSubject = sSubject &amp; oAllMails(i).Subject &amp; vbCrLf\r\n  End If\r\nNext\r\n\r\n'Display the results\r\nmsgbox sSubject\r\n<\/pre>\n<div style=\"width: 443px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"List of Unread Emails in Outlook Inbox\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/unread-mails-in-inbox.png\" alt=\"List of Unread Emails in Outlook Inbox\" width=\"433\" height=\"214\" \/><p class=\"wp-caption-text\">List of Unread Emails in Outlook Inbox<\/p><\/div>\n<p><em>This article just lists few of the important functions of outlook mail items. You can refer Outlook Object Model to find out more about the different properties and methods that can be used with outlook mail items.<\/em><br \/>\n<span><br \/>\n<\/span><\/p>\n<\/div>\n<p style=\"border: 1px solid #C38EC7; padding: 3mm; background: #EBDDE2;\"><strong>If you feel that we have missed out any important concept, or if you want any other topic to be covered here, please leave a comment or just drop in a mail to us. We&#8217;ll be more than happy to work on it.<\/strong><\/p>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p>If you enjoyed this article, <strong>you can join our blog to get new posts delivered directly in your inbox<\/strong>.<\/p>\n<form style=\"text-align: center;\" action=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify\" method=\"post\" onsubmit=\"window.open('http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=automationrepository\/feeds', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\" target=\"popupwindow\"><input style=\"width: 160px; height: 20px;\" onfocus=\"if (this.value == 'Enter Your Email Address') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Enter Your Email Address';}\" type=\"text\" value=\"Enter Your Email Address\" \/> <input type=\"hidden\" name=\"uri\" value=\"automationrepository\/feeds\" \/> <input type=\"hidden\" name=\"loc\" value=\"en_US\" \/> <input type=\"submit\" value=\"Join Us\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n<p><span><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you would see how to access emails in outlook, how to send emails using outlook and how to access different properties of an email item. To access email items, you can use MailItem class which contains the methods and properties to work with email items.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,9],"tags":[54],"class_list":["post-1007","post","type-post","status-publish","format-standard","hentry","category-advanced-concepts","category-qtp-concepts","tag-automating-outlook-using-qtp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Part 5: Automating Outlook using QTP | Emails in Outlook - XX<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anish Pillai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/\",\"name\":\"Part 5: Automating Outlook using QTP | Emails in Outlook - XX\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png\",\"datePublished\":\"2012-01-15T19:31:50+00:00\",\"dateModified\":\"2012-01-15T19:49:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Part 5: Automating Outlook using QTP | Emails in Outlook\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/\",\"name\":\"XX\",\"description\":\"\\r\\nasas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\",\"name\":\"Anish Pillai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"caption\":\"Anish Pillai\"},\"description\":\"Find more about Anish Pillai on Google+\",\"sameAs\":[\"http:\/\/www.automationrepository.com\"],\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Part 5: Automating Outlook using QTP | Emails in Outlook - XX","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/","name":"Part 5: Automating Outlook using QTP | Emails in Outlook - XX","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png","datePublished":"2012-01-15T19:31:50+00:00","dateModified":"2012-01-15T19:49:24+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/email-message-properties.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-emails-in-outlook\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Part 5: Automating Outlook using QTP | Emails in Outlook"}]},{"@type":"WebSite","@id":"https:\/\/www.automationrepository.com\/wordpress\/#website","url":"https:\/\/www.automationrepository.com\/wordpress\/","name":"XX","description":"\r\nasas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20","name":"Anish Pillai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","caption":"Anish Pillai"},"description":"Find more about Anish Pillai on Google+","sameAs":["http:\/\/www.automationrepository.com"],"url":"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/"}]}},"_links":{"self":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/1007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1007"}],"version-history":[{"count":5,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/1007\/revisions"}],"predecessor-version":[{"id":1015,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/1007\/revisions\/1015"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}