Skip to content

Instantly share code, notes, and snippets.

@royashbrook
Created March 24, 2018 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royashbrook/3353edb7ce8f9e739ab9d0757118a201 to your computer and use it in GitHub Desktop.
Save royashbrook/3353edb7ce8f9e739ab9d0757118a201 to your computer and use it in GitHub Desktop.
Send-MailMessage Bug
<?xml version="1.0"?>
<settings>
<mail>
<from>from@gmail.com</from>
<to>to@gmail.com</to>
<subject>Test</subject>
<smtp>smtp.gmail.com</smtp>
<port>587</port>
<user>from@gmail.com</user>
<pass>frompassword</pass>
</mail>
</settings>
FROM microsoft/powershell
RUN mkdir /smmbug
ADD . /smmbug
ENTRYPOINT ["pwsh", "/smmbug/job.ps1"]
Set-Location (Split-Path -Parent $MyInvocation.MyCommand.Path)
[xml]$cfg = Get-Content "config.xml"
$m = $cfg.settings.mail
$sp = ConvertTo-SecureString $m.pass -AsPlainText -Force
$c = New-Object pscredential ($m.user, $sp)
$files = ([string[]]((gci)|%{$_.name}))
$msg = @{
Port = $m.port
Credential = $c
From = $m.from
To = $m.to
Subject = $m.subject
Attachments = $files
SmtpServer = $m.smtp
UseSsl = $true
}
"---sending the following files:"
$files
Send-MailMessage @msg
"---sent"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment