Shane Thomas
Shane Thomas

Reputation: 15

Mail Automation Task using Powershell

I had been trying to automate the process of sending mails along with attachments via my outlook account using Powershell.

$OL = New-Object -ComObject outlook.application

Start-Sleep 5

<#
olAppointmentItem
olContactItem
olDistributionListItem
olJournalItem
olMailItem
olNoteItem
olPostItem
olTaskItem
#>

#Create Item
$mItem = $OL.CreateItem("olMailItem")

$mItem.To = "[email protected]"
$mItem.Subject = "PowerMail"
$mItem.Body = "SENT FROM POWERSHELL"

$mItem.Send()

Stuck with adding attachments in the code. Please help me out.

Upvotes: 0

Views: 411

Answers (1)

Steven
Steven

Reputation: 7087

Look at the documentation here.

In your case something like:

$mItem.Attachments.Add( "C:\My Documents\Q496.xls", olByValue, 1, "4th Quarter 1996 Results Chart"

Arguments are Source, Type, Position & DisplayName.

Upvotes: 0

Related Questions