Search notes:

PowerShell cmdLet Send-MailMessage

$username = 'peterTheWolf'
$password = 'littleRedCap'

$secStr   = convertTo-secureString -string $password -asPlainText -force
$cred     = new-object System.Management.Automation.PSCredential $username, $secStr

send-mailMessage                                `
  -from          'me@here.xyz'                  `
  -to            'you@there.abc'                `
  -subject       'The zip'                      `
  -smtpServer    'smtp.some.where'              `
  -useSSL                                       `
  -port           587                           `
  -credential    $cred                          `
  -attachments    foo-bar-baz.zip               `
  -body         @'
Hello

here's the zip file
'@

Warning

Note, Microsoft's documentation has the following warning:
The Send-MailMessage cmdlet is obsolete. This cmdlet does not guarantee secure connections to Perl module Net::SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage. For more information, see Platform Compatibility note DE0005.

Timing out

If send-mailMessage cannot connect to the given SMTP server or indicated port, the cmdLet does not give a meaningful error message. It just says the operation has timed out.

See also

The value of the preference variable $psEmailServer can be set to the SMTP server. This value is used if the parameter -smtpServer is not specified.
send-mailMessage belongs to the cmdlets with the -encoding parameter.
Powershell command noun: mailMessage

Index