<?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>Scripting Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/development/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/development/scripting/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 12:46:09 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Sending an email with attachments using Outlook and PowerShell</title>
		<link>https://blogit.create.pt/andresilva/2017/12/07/sending-an-email-with-attachments-using-outlook-and-powershell/</link>
					<comments>https://blogit.create.pt/andresilva/2017/12/07/sending-an-email-with-attachments-using-outlook-and-powershell/#comments</comments>
		
		<dc:creator><![CDATA[André Silva]]></dc:creator>
		<pubDate>Thu, 07 Dec 2017 17:54:38 +0000</pubDate>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Automatic Testing]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Automation]]></category>
		<guid isPermaLink="false">http://blogit.create.pt/andresilva/?p=174</guid>

					<description><![CDATA[<p>A few days ago, I had to find a way to automatically send an email with attachments, at a predetermined time, using Outlook and PowerShell. I decided to use a Windows Scheduled Task, that would wake up at that time and invoke a PowerShell script. The script below is the result of a collection of [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/andresilva/2017/12/07/sending-an-email-with-attachments-using-outlook-and-powershell/">Sending an email with attachments using Outlook and PowerShell</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A few days ago, I had to find a way to automatically send an email with attachments, at a predetermined time, using Outlook and PowerShell. I decided to use a Windows Scheduled Task, that would wake up at that time and invoke a PowerShell script.</p>
<p>The script below is the result of a collection of snippets and bits of code I found in various places around the Internet that allowed me to solve this problem.</p>
<p>For this example, I only want to send the files which have a specific extension (<strong>.html</strong>) and that exist in a specific folder (passed as parameter to the PowerShell script). Of course, you are free to remove this extension filtering for your own purposes.</p>
<p>Also, note that Outlook must have a configured email account for the sending process to succeed.</p>
<pre class="brush: powershell; title: ; notranslate">
# Check to see we have all the arguments
if($args.Count -lt 1)
{
Write-Host &quot;Use: SendMail.ps1 &lt;Path&gt;&quot;
Write-Host
Write-Host &quot; &lt;Path&gt;: Full path for the folder which contains the files&quot;
Write-Host
exit
}

$FullPath=$args&#x5B;0]

#Get an Outlook application object

$o = New-Object -com Outlook.Application

$mail = $o.CreateItem(0)

#2 = High importance message
$mail.importance = 2

$mail.subject = &quot;This is the subject of the mail&quot;
$mail.body = &quot;This is the body of the email. It has been automatically generated by a script.&quot;

#separate multiple recipients with a &quot;;&quot;
$mail.To = &lt;INSERT THE RECIPIENT HERE&gt;
#$mail.CC = &lt;OTHER RECIPIENT 1&gt;;&lt;OTHER RECIPIENT 2&gt;

# Iterate over all files and only add the ones that have an .html extension
$files = Get-ChildItem $FullPath

for ($i=0; $i -lt $files.Count; $i++) {

$outfileName = $files&#x5B;$i].FullName
$outfileNameExtension = $files&#x5B;$i].Extension

# if the extension is the one we want, add to attachments
if($outfileNameExtension -eq &quot;.html&quot;)
{
$mail.Attachments.Add($outfileName);
}
}

$mail.Send()

# give time to send the email
Start-Sleep 20

# quit Outlook
$o.Quit()

#end the script
exit
</pre>
<p>You can invoke the script presented above, by using a simple command window and giving the following command:</p>
<p><a href="http://blogit-create.com/wp-content/uploads/2017/12/PowerShellCommand.png"><img decoding="async" class="aligncenter size-full wp-image-224" src="http://blogit-create.com/wp-content/uploads/2017/12/PowerShellCommand.png" alt="PowerShell Command" width="544" height="75" srcset="https://blogit.create.pt/wp-content/uploads/2017/12/PowerShellCommand.png 544w, https://blogit.create.pt/wp-content/uploads/2017/12/PowerShellCommand-300x41.png 300w, https://blogit.create.pt/wp-content/uploads/2017/12/PowerShellCommand-534x75.png 534w" sizes="(max-width: 544px) 100vw, 544px" /></a></p>
<p>I hope this helps!</p>
<p>The post <a href="https://blogit.create.pt/andresilva/2017/12/07/sending-an-email-with-attachments-using-outlook-and-powershell/">Sending an email with attachments using Outlook and PowerShell</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/andresilva/2017/12/07/sending-an-email-with-attachments-using-outlook-and-powershell/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
