The Send-MailMessage PowerShell command is a powerful tool for sending emails from the command line. It is part of the Windows PowerShell module, which is a collection of commands used to manage and automate tasks in Windows. With the Send-MailMessage command, you can easily send emails from the command line with just a few simple parameters.

The syntax for the Send-MailMessage command is as follows:

Send-MailMessage -From <String> -To <String[]> -Subject <String> -Body <String> [-Attachments <String[]>] [-Bcc <String[]>] [-Cc <String[]>] [-DeliveryNotificationOption <DeliveryNotificationOptions>] [-Encoding <Encoding>] [-Priority <MailPriority>] [-SmtpServer <String>] [-UseSsl] [-Credential <PSCredential>] [-Port <Int32>] [-BodyAsHtml] [-Confirm] [-WhatIf] [<CommonParameters>]

Parameters

The Send-MailMessage command has several parameters that can be used to customize the email message. The parameters are as follows:

Parameter Description
From The email address of the sender.
To The email address of the recipient.
Subject The subject of the email message.
Body The body of the email message.
Attachments The file or files to be attached to the email message.
Bcc The email address of the blind carbon copy recipient.
Cc The email address of the carbon copy recipient.
DeliveryNotificationOption The delivery notification option for the email message.
Encoding The encoding for the email message.
Priority The priority of the email message.
SmtpServer The SMTP server to be used for sending the email message.
UseSsl Specifies whether SSL should be used for sending the email message.
Credential The credentials to be used for authentication.
Port The port to be used for sending the email message.
BodyAsHtml Specifies whether the body of the email message should be sent as HTML.
Confirm Prompts the user for confirmation before sending the email message.
WhatIf Displays what would happen if the command were to run without actually running the command.

Inputs

The Send-MailMessage command requires the following inputs:

  • From: The email address of the sender.
  • To: The email address of the recipient.
  • Subject: The subject of the email message.
  • Body: The body of the email message.

Outputs

The Send-MailMessage command does not produce any output.

Examples

The following example shows how to use the Send-MailMessage command to send an email message from the command line:

Send-MailMessage -From “[email protected]” -To “[email protected]” -Subject “Test Email” -Body “This is a test email message.”

Tips

The following tips can help you get the most out of the Send-MailMessage command:

  • Be sure to specify the correct SMTP server and port when sending the email message.
  • If you need to authenticate with the SMTP server, use the Credential parameter.
  • If you need to send an HTML email message, use the BodyAsHtml parameter.
  • If you need to attach files to the email message, use the Attachments parameter.
  • If you need to send a blind carbon copy or a carbon copy, use the Bcc and Cc parameters.
  • If you need to specify a delivery notification option, use the DeliveryNotificationOption parameter.
  • If you need to specify a priority for the email message, use the Priority parameter.
  • If you need to specify an encoding for the email message, use the Encoding parameter.
  • If you need to use SSL for sending the email message, use the UseSsl parameter.
  • If you need to confirm before sending the email message, use the Confirm parameter.
  • If you need to see what would happen if the command were to run without actually running the command, use the WhatIf parameter.

Conclusion

The Send-MailMessage command is a powerful tool for sending emails from the command line. With the command, you can easily send emails with just a few simple parameters. The command has several parameters that can be used to customize the email message, and it can be used to send HTML emails, attach files, and more. With these tips, you should be able to get the most out of the Send-MailMessage command.

Leave a Reply