Email

Example

$emailSmtpServer = "mail.somewhere.com"
$emailFrom = "John Smith <john@somewhere.com>"
$emailTo = "jane@somewhere.com"
$emailSubject = "Testing e-mail"
$emailBody = @"
Here is a message
From your friendly neighborhood IT guy
"@
Send-MailMessage -To $emailTo -From $emailFrom -Subject $emailSubject -Body $emailBody -SmtpServer $emailSmtpServer

Send a mail using CLI

Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port SMTPPort

Send mail using a hash table

$message = @{
    from = "noreply@lmwindpower.com"
    to      = $to
    cc      = $cc
    subject = "Group Membership: $group in $domain"
    body    =  $messagebody
    attachments = $members
    smtpserver = "e2ksmtp01.e2k.ad.gtm.ge.com"
  }

Send-MailMessage @message

Send mail using parameters

#define the parameters
param (
    [string[]]$to = $to.split(',')
)

$messagebody =  @"
This is a test email sent using paramters:

Parameter "to" = $to
"@

$message = @{
    from = "noreply@lmwindpower.com"
    to      = $to
    subject = "Testing2"
    body    =  $messagebody
    #attachments = 
    smtpserver = "e2ksmtp01.e2k.ad.gtm.ge.com"
  }
  
Send-MailMessage @message
Last modified July 21, 2024: update (e2ae86c)