Created
August 8, 2017 00:10
-
-
Save kianting/395744d1af1b08e36874530b43620c4d to your computer and use it in GitHub Desktop.
Powershell Script to Send E-Mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
#.SYNOPSIS | |
#Sends SMTP email via the Hub Transport server | |
# | |
#.EXAMPLE | |
#.Send-Email.ps1 -To "administrator@exchangeserverpro.net" -Subject "Test email" -Body "This is a test" | |
# | |
param( | |
[string]$to, | |
[string]$subject, | |
[string]$body | |
) | |
$SmtpUser = "rammsappworkorder@outlook.com" | |
$smtpPassword = "mulesoft2017" | |
$SMTPServer = "smtp-mail.outlook.com" | |
$SMTPPort = "587" | |
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force) | |
$smtpFrom = "bill.gates@mulesoft.com" | |
$smtpTo = $to | |
$bcc = "warrenbuffet@gmail.com" | |
$messageSubject = $subject | |
$messageBody = $body | |
$mail = New-Object System.Net.Mail.MailMessage | |
$mail.from = "bill.gates@mulesoft.com" | |
$mail.to.Add($smtpTo) | |
$mail.Subject = $messageSubject | |
$mail.Body = $messageBody | |
$mail.IsBodyHtml = $true | |
#Send-MailMessage -SmtpServer $SMTPServer -From $smtpFrom -To $smtpTo -Bcc $bcc -Subject $messageSubject -Body $messageBody -UseSsl false -Credential $Credentials | |
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort); | |
$smtp.UseDefaultCredentials = $false; | |
$smtp.EnableSSL = $true | |
$smtp.Credentials = New-Object System.Net.NetworkCredential($SmtpUser, $smtpPassword); | |
#$smtp.Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $SmtpUser, $($smtpPassword | ConvertTo-SecureString -AsPlainText -Force) | |
$smtp.Send($mail); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment