{"id":700,"date":"2011-11-17T00:12:56","date_gmt":"2011-11-16T18:42:56","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=700"},"modified":"2011-11-18T01:15:42","modified_gmt":"2011-11-17T19:45:42","slug":"how-to-send-emails-using-qtp-from-gmail-and-yahoo","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/","title":{"rendered":"How to send emails using QTP from Gmail and Yahoo"},"content":{"rendered":"<div style=\"font-family: Verdana; text-align: justify;\">\n<p style=\"text-align: justify;\">This article shows how you can use QTP to send mails to any email address using email service providers such as GMail, Yahoo Mail etc. Automatically sending mails through QTP can be a very nice enhancement to your automation framework. For example, after you run your test scripts, you need to email test run reports<!--more--> (number of test scripts passed \/ failed etc) to the stakeholders. You can automate this mailing process and send custom reports to the required people.<\/p>\n<div style=\"width: 407px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"Send Email from Gmail and Yahoo Mail\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png\" alt=\"Send Email from Gmail and Yahoo Mail\" width=\"397\" height=\"87\" \/><p class=\"wp-caption-text\">Send Email from Gmail and Yahoo Mail<\/p><\/div>\n<p style=\"text-align: justify;\">Before going through the code, lets go through some important points regarding the code &#8211;<\/p>\n<p style=\"text-align: justify;\"><strong>1.<\/strong> The below given email code is not directly related to QTP as such. The code is actually a VBScript function which you can use in QTP. So even if you don&#8217;t have QTP, you can use this VBScript code directly.<\/p>\n<p style=\"text-align: justify;\"><strong>2.<\/strong> The email functionality uses Microsoft&#8217;s CDO (Collaboration Data Objects) technology to send mails. You can find more details about Microsoft CDO in Microsoft&#8217;s MSDN Library.<\/p>\n<p style=\"text-align: justify;\"><strong>3.<\/strong> It is not necessary that you have to use this code using VBScript only. Microsoft CDO can be programmed using any language that creates COM object such as ASP, VB, Visual C++, C# etc.<\/p>\n<p style=\"text-align: justify;\"><strong>4.<\/strong> The below code has been tested on Gmail and Yahoo mail. If you want to use this code in your company&#8217;s SMTP server, you need to contact your network team to get details about the SMTP address, port number etc.<\/p>\n<p style=\"text-align: justify;\"><strong>5.<\/strong> To use this code, you don&#8217;t need to have Microsoft Outlook installed on your system. You can also use MS Outlook to send emails (<span style=\"text-decoration: line-through;\">we will discuss this in a separate post<\/span> <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\">Read how to send mails from MS Outlook using QTP<\/a>).<\/p>\n<p style=\"text-align: justify;\">Let&#8217;s now see the code for sending emails using QTP (VBScript) through Gmail.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFunction fnSendEmail()\r\n\r\n'Create an object of CDO type\r\nSet myMail=CreateObject(&quot;CDO.Message&quot;)\r\n'Enable SSL Authentication\r\nmyMail.Configuration.Fields.Item(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpusessl&quot;) = True\r\n'Enable basic smtp authentication\r\nmyMail.Configuration.Fields.Item(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpauthenticate&quot;) = 1\r\n'Specify SMTP server and port\r\nmyMail.Configuration.Fields.Item (&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserver&quot;)=&quot;smtp.gmail.com&quot;\r\nmyMail.Configuration.Fields.Item (&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserverport&quot;) = 25\r\nmyMail.Configuration.Fields.Item (&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendusing&quot;) = 2\r\n'Specify user id and password\r\nmyMail.Configuration.Fields.Item(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendusername&quot;) = &quot;senders_id@gmail.com&quot;\r\nmyMail.Configuration.Fields.Item(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendpassword&quot;) = &quot;**********&quot;\r\n'Update the configuration fields\r\nmyMail.Configuration.Fields.Update\r\n\r\n'Specify email properties\r\nmyMail.Subject = &quot;Sending Email from QTP&quot;\r\nmyMail.From = &quot;senders_id@gmail.com&quot;\r\nmyMail.To = &quot;some_mail_id_1@gmail.com&quot;\r\nmyMail.CC = &quot;&quot;\r\nmyMail.BCC = &quot;&quot;\r\nmyMail.TextBody = &quot;This is the Text Body&quot;\r\n'Send mail\r\nmyMail.Send\r\nSet myMail = Nothing\r\n\r\nEnd Function\r\n<\/pre>\n<p>Using the above code, you can send emails to any email id using your gmail address. Just specify your gmail user id and password in lines 14 &amp; 15. Also mention the email id to which you want to send mails in lines 22, 23 and\/or 24.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong><br \/>\nHow to send mails from your Yahoo mail id<\/strong><\/span><\/p>\n<p>To send mails using your yahoo mail id, you need to replace the Gmail SMTP address and port number with Yahoo&#8217;s SMTP address and port number.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Specify Yahoo SMTP server and Port Number\r\nmyMail.Configuration.Fields.Item (&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserver&quot;)=&quot;smtp.mail.yahoo.com&quot;\r\nmyMail.Configuration.Fields.Item (&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserverport&quot;) = 465\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><br \/>\n<strong>How to send mails to multiple people in one go.<\/strong><\/span><\/p>\n<p>To send mails to multiple email ids in one go, you need to just enter multiple mail ids separated by a semi colon(;). Example:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nmyMail.To = &quot;some_mail_id_1@gmail.com; some_other_id@yahoo.com&quot;\r\nmyMail.CC = &quot;some_mail_id@someaddress.com&quot;\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><br \/>\n<strong>How to send html content in the mail.<\/strong><\/span><\/p>\n<p>Normally you would not send plain text in emails. You would usually be sending some html content in mails. To do so, you need to use HTMLBody in place of TextBody and include html tags in your text body.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'myMail.TextBody = &quot;This is the Text Body&quot;  -&gt; TextBody not to be used\r\nmyMail.HTMLBody = &quot;&lt;html&gt;&lt;table border=1&gt;&lt;tr&gt;Row1&lt;\/tr&gt;&lt;tr&gt;Row2&lt;\/tr&gt;&lt;\/table&gt;&lt;\/html&gt;&quot;\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><br \/>\n<strong>How to send attachments using the email code.<\/strong><\/span><\/p>\n<p>To add an attachment in you mail, you need to include myMail.AddAttachment line in your code and specify the correct path of the file to be attached. To add more than one attachment, repeat myMail.AddAttachment code required number of times.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Specify email mail properties\r\nmyMail.Subject = &quot;Sending Attachment in Mail from QTP&quot;\r\nmyMail.From = &quot;some_id@gmail.com&quot;\r\nmyMail.To = &quot;some_other_id@gmail.com&quot;\r\nmyMail.TextBody= &quot;Mail Content&quot;\r\n'Send 2 attachments in the mail\r\nmyMail.AddAttachment &quot;D:\\Attachment1.txt&quot;\r\nmyMail.AddAttachment &quot;D:\\Attachment2.txt&quot;\r\n\r\nmyMail.Send\r\nset myMail=nothing\r\n<\/pre>\n<div style=\"width: 396px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"Files Attached in Gmail\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/attachments.png\" alt=\"Files Attached in Gmail\" width=\"386\" height=\"112\" \/><p class=\"wp-caption-text\">Files Attached in Gmail<\/p><\/div>\n<p>Try out the above code and see if it works for you. In case if you have any queries regarding the code, please use the comments section or the contact form to let us know about the same.<\/p>\n<\/div>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p>If you liked this article, you can join our blog to get the new posts delivered directly in your inbox.<\/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","protected":false},"excerpt":{"rendered":"<p>This article shows how you can use QTP to send mails to any email address using email service providers such as GMail, Yahoo Mail etc. Automatically sending mails through QTP can be a very nice enhancement to your automation framework. For example, after you run your test scripts, you need to email test run reports<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[50],"class_list":["post-700","post","type-post","status-publish","format-standard","hentry","category-advanced-concepts","tag-email"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to send emails using QTP from Gmail and Yahoo - 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\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/\" \/>\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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/\",\"name\":\"How to send emails using QTP from Gmail and Yahoo - XX\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png\",\"datePublished\":\"2011-11-16T18:42:56+00:00\",\"dateModified\":\"2011-11-17T19:45:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to send emails using QTP from Gmail and Yahoo\"}]},{\"@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":"How to send emails using QTP from Gmail and Yahoo - 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\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/","name":"How to send emails using QTP from Gmail and Yahoo - XX","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png","datePublished":"2011-11-16T18:42:56+00:00","dateModified":"2011-11-17T19:45:42+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/gmail-yahoo-mail.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-send-emails-using-qtp-from-gmail-and-yahoo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"How to send emails using QTP from Gmail and Yahoo"}]},{"@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\/700","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=700"}],"version-history":[{"count":29,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"predecessor-version":[{"id":740,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/700\/revisions\/740"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}