Created
September 23, 2014 06:55
-
-
Save revirth/82f1463b46681b41638a to your computer and use it in GitHub Desktop.
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
#http://stackoverflow.com/questions/12460950/how-to-pass-credentials-to-the-send-mailmessage-command-for-sending-emails | |
$EmailTo = "[email protected]" | |
$EmailFrom = "[email protected]" | |
$Subject = "Test" | |
$Body = "Test Body" | |
$SMTPServer = "smtp.gmail.com" | |
$filenameAndPath = "C:\CDF.pdf" | |
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body) | |
$attachment = New-Object System.Net.Mail.Attachment($filenameAndPath) | |
$SMTPMessage.Attachments.Add($attachment) | |
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) | |
$SMTPClient.EnableSsl = $true | |
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password"); | |
$SMTPClient.Send($SMTPMessage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment