Last active
August 29, 2015 13:57
-
-
Save kparms/9468148 to your computer and use it in GitHub Desktop.
Email in Powershell
This file contains hidden or 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
| function sendMail([string]$arg1){ | |
| Write-Host "Sending Email" | |
| #SMTP server name | |
| $smtpServer = "SMTPSERVERNAME" | |
| $msg = new-object Net.Mail.MailMessage | |
| $smtp = new-object Net.Mail.SmtpClient($smtpServer) | |
| #Email structure | |
| $msg.From = "from@address.com" | |
| $msg.To.Add("to@address.com") | |
| $msg.subject = "My Subject" | |
| $msg.body = $arg1 | |
| #attachment (if necessary) | |
| $logfile = "d:\folder\file.txt" | |
| $attach = new-object Net.Mail.Attachment($logfile) | |
| $msg.Attachments.Add($attach) | |
| #Sending email | |
| $smtp.Send($msg) | |
| Write-Host "Email Sent" | |
| } | |
| sendMail("This is my message") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment