Skip to content

Instantly share code, notes, and snippets.

@shane0
Created June 6, 2015 07:51
Show Gist options
  • Save shane0/5512d8900705424365c9 to your computer and use it in GitHub Desktop.
Save shane0/5512d8900705424365c9 to your computer and use it in GitHub Desktop.
powershell send mail using gmail
$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
@shane0
Copy link
Author

shane0 commented Jun 6, 2015

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

@shane0
Copy link
Author

shane0 commented Nov 4, 2018


$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