-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSend-365Email.ps1
More file actions
23 lines (20 loc) · 889 Bytes
/
Send-365Email.ps1
File metadata and controls
23 lines (20 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Get the credential
$credential = Get-Credential
$UserName = Read-Host "Enter Users Full Name"
$UserEmail = Read-Host "Enter Users Email"
#Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName username@yourdomain.com
## Define the Send-MailMessage parameters
$mailParams = @{
SmtpServer = 'smtp.office365.com'
Port = '587' # or '25' if not using TLS
UseSSL = $True ## or not if using non-TLS
Credential = $credential
From = 'from@yourdomain.com'
To = 'to@yourdomain.com'
Subject = "subject line can use variables"
Body = "body of email and can use variables here too"
DeliveryNotificationOption = 'OnFailure', 'OnSuccess'
}
## Send the message
Send-MailMessage @mailParams