Send mail from powershell
You can send an email from PowerShell using the Send-MailMessage
cmdlet. Here's an example of how to use it:
Send-MailMessage -To "[email protected]" -From "[email protected]" -Subject "Test Email" -Body "This is a test email sent from PowerShell"
This will send an email to the recipient with the specified subject and body.
You can also specify additional parameters, such as:
-SmtpServer
: specifies the SMTP server to use (e.g.smtp.example.com
)-Attachments
: specifies one or more files to attach to the email-Priority
: specifies the priority of the email (e.g.High
,Normal
,Low
)-Encoding
: specifies the encoding of the email body (e.g.UTF8
,ASCII
)
Here's an example that includes some of these additional parameters:
Send-MailMessage -To "[email protected]" -From "[email protected]" -Subject "Test Email" -Body "This is a test email sent from PowerShell" -SmtpServer "smtp.example.com" -Attachments "C:\Path\To\File1.txt", "C:\Path\To\File2.pdf" -Priority High -Encoding UTF8
Note that you need to have the Send-MailMessage
cmdlet installed and configured on your system. If you're running PowerShell on a Windows system, this cmdlet is included by default. If you're running PowerShell on a Linux or macOS system, you may need to install the Send-MailMessage
cmdlet separately.
Also, make sure to replace the placeholders ([email protected]
, [email protected]
, smtp.example.com
, etc.) with the actual values for your email account and server.