Created
June 6, 2015 07:51
-
-
Save shane0/5512d8900705424365c9 to your computer and use it in GitHub Desktop.
powershell send mail using gmail
This file contains 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
$param = @{ | |
SmtpServer = 'smtp.gmail.com' | |
Port = 587 | |
UseSsl = $true | |
Credential = Get-Credential [email protected] | |
From = '[email protected]' | |
To = '[email protected]' | |
Subject = 'editme' | |
Body = "editme" | |
Attachments = c:\file.txt | |
} | |
Send-MailMessage @param |
$filepath = @()
$filepath += 'E:\Folder\file1.txt'
$filepath += 'E:\Folder\file2.txt'
# Write-Host $filepath
foreach($_ in $filepath){
Write-Host $_
}
$emailparam = @{
From = '[email protected]'
To = '[email protected]'
Attachments = $filepath
}
Write-Host $emailparam.Attachments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gmail doesn't like this, won't work at first, I think gmail wants explicit tls auth, by default this library default is implicit
you'll receive auth errors but eventually you'll receive an email that warns you about this access atempt, yet the links in that email let you enable insecure app access
https://www.google.com/settings/security/lesssecureapps