-
Notifications
You must be signed in to change notification settings - Fork 0
/
Outlook_Send_Email.ps1
42 lines (38 loc) · 1.33 KB
/
Outlook_Send_Email.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#Read Me:
Developed By:
Name:Vaneeswaran N
www.vaneeswaran.com
#Function Name : Send_Email
#Descrption : Used to Send Mail
#Argument : Subject and Body of the Mail
#
#Note : This script expects the outlook app installed and configured in your machine where you are executing this scripts
#>
function Send_Email($To, $Subject, $Body)
{
echo "Sending Email Started.... "
try
{
$olFolderInbox = 6
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To =$To
$Mail.Subject = $Subject
$Mail.Body =$Body
if($Body.length -gt 10) #Check to mail body is more than 10 char
{
$Mail.Send()
$global:Function_Status = $true
}
Remove-Variable Outlook
Remove-Variable Mail
}
catch
{
write-host “Caught an exception:” -ForegroundColor Red
write-host “Exception Type: $($_.Exception.GetType().FullName)” -ForegroundColor Red
write-host “Exception Message: $($_.Exception.Message)” -ForegroundColor Red
}
echo "Sending Email Completed.... "
}
Send_Email testme@gmail.com "Mail Subject here" "Mail Body Here"