Uncategorized

Send Email from Power shell

Below script will help to send an attachment as an email.

http://www.techrepublic.com/blog/windows-and-office/send-an-email-with-an-attachment-using-powershell/

Sample script

Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue

$file = “\\server\share\abc.txt”

$smtpServer = “192.168.100.1”

$att = new-object Net.Mail.Attachment($file)

$msg = new-object Net.Mail.MailMessage

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = “xyz@abc.com”

$msg.To.Add(“hlm@abc.com”)

$msg.To.Add(“bbb@abc.com”)

$msg.Subject = “Notification from email server”

$msg.Body = “Attached is text file”

$msg.Attachments.Add($att)

$smtp.Send($msg)

$att.Dispose()

 

 

Advertisements
Standard

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s