Send an email using PowerShell

function sendMail{

Write-Host “Sending Email”

#SMTP server name
$smtpServer = “something.something.com” #–Enter your SMTP server name

#Creating a Mail object
$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

#Email structure
$msg.From = “admin@SharePoint.com”

$msg.To.Add(“John.Doe@contoso.com”)
$msg.subject = “Email Test”
$msg.body = Get-Content C:\Emailbody.txt

#Sending email
$smtp.Send($msg)

}

#Calling function
sendMail

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