Sending Email using Power Shell script

Below are the two ways which you can use to send an email using power shell

Way 1:

$EmailFrom = “abc@sample.com”
$EmailTo = “xyz@smaple.com”
$Subject = “Test Email Using Power Shell”
$Body = “Hi, This is test email.”
$SMTPServer = “smtp.server”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“”, “”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Way 2:

Send-MailMessage -From “abc@sample.com” -To “xyz@sample.com” -SmtpServer “SmtpServerIP” -Subject “Subject for Email” -Body “Email Body” -BodyAsHtml

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s