Securely send emails with attachments
$credential = Get-Credential
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }
Send-MailMessage `
-SmtpServer 172.XXX.XXX.XXX `
-port 587 `
-UseSsl `
-Credential $credential `
-From "Nordine Ben Bachir <[email protected]>" `
-To "xxxxxx" `
-Bcc "xxxxxxxxxx"`
-Subject "Don t forget today s meeting!" `
-Body "Test email with Ssl (port58)7"
-Attachments @(Get-ChildItem "C:\nordinetest\" | % { $_.FullName })
All attachment will have the mimetype application/octet-stream
$ swaks -s "${smtpserver}" -p "${smtpport}" -t "$to" -f "$from" --header "Subject: $subject" -S \
--protocol ESMTP -a -au "$user" -ap "$password" --body "$body" \
--attach foo.pdf --attach bar.jpg
Or manually specifiy MIME type
$ swaks -s "${smtpserver}" -p "${smtpport}" -t "$to" -f "$from" --header "Subject: $subject" -S \
--protocol ESMTP -a -au "$user" -ap "$password" --body "$body" \
--attach-type "$(get_mimetype foo.pdf)" --attach foo.pdf \
--attach-type "$(get_mimetype bar.jpg)" --attach bar.jpg
the mimetype MUST be before the file name.
- To do SSL/TLS, see the various --tls* options