forked from DivineOps/PowerShell-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-mail-o365.ps1
41 lines (33 loc) · 1.2 KB
/
send-mail-o365.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
$MyCredential = "automationCredential"
$Body = "Content of mail"
$subject = "Mail send from Azure Automation using Office 365"
$userid='[email protected]'
# Get the PowerShell credential and prints its properties
$Cred = Get-AutomationPSCredential -Name $MyCredential
if ($Cred -eq $null)
{
Write-Output "Credential entered: $MyCredential does not exist in the automation service. Please create one `n"
}
else
{
$CredUsername = $Cred.UserName
$CredPassword = $Cred.GetNetworkCredential().Password
Write-Output "-------------------------------------------------------------------------"
Write-Output "Credential Properties: "
Write-Output "Username: $CredUsername"
Write-Output "Password: *************** `n"
Write-Output "-------------------------------------------------------------------------"
# Write-Output "Password: $CredPassword `n"
}
Send-MailMessage `
-To '[email protected]' `
-Subject $subject `
-Body $Body `
-UseSsl `
-Port 587 `
-SmtpServer 'smtp.office365.com' `
-From $userid `
-BodyAsHtml `
-Credential $Cred
Write-Output "Mail is now send `n"
Write-Output "-------------------------------------------------------------------------"