<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ASI &#187; createobject</title>
	<atom:link href="http://www.asi-test.com/ASI/tag/createobject/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.asi-test.com/ASI</link>
	<description>Automated Solutions, Inc. - Leadership in Software Development, Testing &#38; Test Automation</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:38:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>QTP: Send Outlook Email</title>
		<link>http://www.asi-test.com/ASI/qtp-send-outlook-email/</link>
		<comments>http://www.asi-test.com/ASI/qtp-send-outlook-email/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 16:32:19 +0000</pubDate>
		<dc:creator>Shawn</dc:creator>
				<category><![CDATA[QuickTest Pro]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[createobject]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[subroutine]]></category>

		<guid isPermaLink="false">http://www.asi-test.com/ASI/?p=82</guid>
		<description><![CDATA[QuickTest Pro sample code &#8211; sending an email using Outlook This QuickTest Pro code sample shows how you can create a subroutine that will send an email using Microsoft Outlook.  The subroutine is defined and can either be placed at the top of your script (must be executed first before it is called in order for [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">QuickTest Pro sample code &#8211; sending an email using Outlook</p>
<p style="text-align: left;">This QuickTest Pro code sample shows how you can create a subroutine that will send an email using Microsoft Outlook.  The subroutine is defined and can either be placed at the top of your script (must be executed first before it is called in order for the script to know about the subroutine) or it can be placed in a Function Library and associated with the test script. </p>
<p><span id="more-82"></span> The reason to use a subroutine is to isolate the process code that creates and sends the Outlook email to a common subroutine in order to take advantage of reuse.  This way every time a test script needs to send an email it just needs to have the bottom three lines of code shown below in the code image (lines 35 &#8211; 37).  It utilizes the &#8220;CreateObject&#8221; to create an instance of the Outlook application in order to create the actual email.  The data used in the email is passed into the subroutine using an array and then each element is referenced within the subroutine code.</p>
<table style="height: 650px;" border="0" cellspacing="0" cellpadding="0" width="574" align="center">
<colgroup span="1">
<col span="1" width="235"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="235" height="20"><img class="size-full wp-image-84 alignnone" title="Outlook email code" src="http://www.asi-test.com/ASI/wp-content/uploads/2010/01/Outlook-email-code.png" alt="Outlook email code" width="559" height="634" /></td>
</tr>
</tbody>
</table>
<p style="margin-left: 10px;">Here is the result of sending the email, the email was received and it looks like this:</p>
<table border="0" cellspacing="0" cellpadding="0" width="455" align="center">
<colgroup span="1">
<col span="1" width="235"></col>
</colgroup>
<tbody>
<tr height="20">
<td width="235" height="20"><img class="size-full wp-image-83 alignleft" title="Outlook sample email" src="http://www.asi-test.com/ASI/wp-content/uploads/2010/01/Outlook-sample-email.png" alt="Outlook sample email" width="470" height="305" /></td>
</tr>
</tbody>
</table>
<p style="margin-left: 10px;">This is kind of a neat feature that you may find a need for.</p>
<p style="margin-left: 10px;">In addition to the images above, here is a snippet of the code for easier readability and the ability to copy the code for your own use:</p>
<table border="2" width="680" align="center" bgcolor="silver">
<tbody>
<tr>
<td><code><br />
<span style="color: black; font-size: small;"><br />
Sub CreateEmail (emailInfo)</span></code><span style="color: black; font-size: small;">Dim objOutl, objMailMsg, objNameSpace, intRecipientCounter, strEmailAddress</span><span style="color: black; font-size: small;">Const olMailItem = 0      &#8217; Constants for new items<br />
Const olAppointmentItem = 1<br />
Const olContactItem = 2<br />
Const olTaskItem = 3<br />
Const olJournalItem = 4<br />
Const olNoteItem = 5<br />
Const olPostItem = 6</span><span style="color: black; font-size: small;">intRecipientCounter=1      &#8217;Start the email address counter at 1</span><span style="color: black; font-size: small;">Set objOutl=CreateObject (&#8220;Outlook.Application&#8221;)   &#8217;Create an Outlook object<br />
Set objMailMsg=objOutl.CreateItem(olMailItem)      &#8217;Create a new Outlook mail object<br />
objMailMsg.Recipients.Add(emailInfo(0))         &#8217;Add the email address to the recipient list of the message<br />
objMailMsg.Subject=emailInfo(1)            &#8217;Set the subject of the message<br />
objMailMsg.Body=emailInfo(2)            &#8217;Set the body of the mail message<br />
objMailMsg.Send               &#8217;Send the mail message</span><span style="color: black; font-size: small;">&#8216;Free up the memory<br />
Set objOutl=Nothing<br />
Set objMailMsg=Nothing</span><span style="color: black; font-size: small;">End Sub</span><span style="color: black; font-size: small;">&#8216;Script code to actually call the subroutine with data to be used in the email that will be sent<br />
Dim emailInfo<br />
emailInfo = Array(&#8220;test@hotmail.com&#8221;,&#8221;Subject: QTP Test email&#8221;,&#8221;Desc: This is a test email sent by QTP&#8221;)<br />
CreateEmail (emailInfo)<br />
</span></td>
</tr>
</tbody>
</table>
<p>Good Luck.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=282419851791791&amp;xfbml=1" type="text/javascript"></script>
<fb:like href="http://www.asi-test.com/ASI/qtp-send-outlook-email/" send="true" layout="button_count" show_faces="true" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.asi-test.com/ASI/qtp-send-outlook-email/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

