---
title: "Send Emails Effortlessly with Send-MailMessage PowerShell Cmdlet"
description: "Master the Send-MailMessage PowerShell cmdlet and send emails in various ways."
canonical: "https://adamtheautomator.com/send-mailmessage/"
---

# Send Emails Effortlessly with Send-MailMessage PowerShell Cmdlet

> Master the Send-MailMessage PowerShell cmdlet and send emails in various ways.

Source: https://adamtheautomator.com/send-mailmessage/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Send Emails Effortlessly with Send-MailMessage PowerShell Cmdlet](https://adamtheautomator.com/wp-content/uploads/2019/08/email-3249062_1280.png)

# Send Emails Effortlessly with Send-MailMessage PowerShell Cmdlet

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)2 August 20196 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [The SMTP Server](#the-smtp-server)
*   [Port](#port)
*   [Recipients and Originators](#recipients-and-originators)
*   [The To, Cc and Bcc Parameters in the Send-Mailmessage Cmdlet](#the-to-cc-and-bcc-parameters)
*   [The From Parameter](#the-from-parameter)
*   [Body](#body)
*   [Sending HTML Body Emails](#sending-html-body-emails)
*   [Encoding](#encoding)
*   [Attachments](#attachments)
*   [Secure and Authenticated Email](#secure-and-authenticated-email)
*   [Assigning Email Priority](#assigning-email-priority)
*   [Delivery Notifications](#delivery-notifications)
*   [Summary](#summary)
*   [Further Reading](#further-reading)

For this PowerShell cmdlet of the day, we’re covering the PowerShell cmdlet Send-MailMessage. This PowerShell cmdlet serves one purpose and one purpose only; to send email in a _lot_ of different ways.

Since there are so many ways the Send-MailMessage cmdlet can send email messages, let’s dive right in and start covering all of the common examples you may run into. In this article, we’re going to cover many examples ranging from the simplest all the way up to some scenarios that I wish upon no one!

This post will be a great resource to bookmark in case you ever come across instances where you need to send email with PowerShell and forget the syntax.

## The SMTP Server

All email has to go through an SMTP server somewhere via a server and a port. To specify a the SMTP server to use, use a parameter called `SMTPServer` that allows you to specify the SMTP server to establish a connection and relay mail through. However, it is not required.

If you don’t specify a value for the `SMTPServer` parameter, the value stored in the `$PSEmailServer` preference variable will be used. You can assign a value to this variable just like you would any other variable.

```powershell
PS51> $PSEmailServer = 'smtp.server.local'
```

However, this variable does not live across [PowerShell](https://adamtheautomator.com/tag/powershell/) sessions. This means you must define it every time a new PowerShell session is open. For this reason, I recommend either using it by defining it above your `Send-MailMessage` reference or not defining it all. Instead, I’d personally provide the `SMTPServer` parameter value. This way you don’t have to manage an outside variable that might change on you.

```powershell
PS51> Send-MailMessage -SmtpServer 'smtp.server.local'
```

### Port

By default, the value that the cmdlet will attempt to send an email through the SMTP server is port 25. This is plain, unencrypted SMTP. However, nowadays, it’s more common to send encrypted email using SSL/TLS (We’ll cover these scenarios later).

If you need to change the port from 25, you can use the `Port` parameter.

```powershell
PS51> Send-MailMessage -SmtpServer 'smtp.server.local' -Port 587
```

## Recipients and Originators

To send an email to different recipients via methods like the _To_, _Cc_ and _Bcc_ fields, the cmdlet has various parameters to accommodate this.

### The To, Cc and Bcc Parameters in the Send-Mailmessage Cmdlet

The cmdlet has three parameters each supporting multiple recipients separated by a comma called `To`, `Cc` and `Bcc`.

You can specify single addresses like below.

```powershell
PS51> Send-MailMessage -To joe@gmail.com -Cc bob@gmail.com -Bcc susie@hotmail.com -Subject 'this is a subject'
```

Or you can specify multiple recipients for each parameter value.

```powershell
PS51> Send-MailMessage -To joe@gmail.com, tony@mycompany.local -Cc bob@gmail.com, rick@othercompany.com -Bcc susie@hotmail.com,secret@fooorg.org -Subject 'this is a subject'
```

### The From Parameter

When sending email, you can also specify the `From` parameter which will set the reply-to header in the email. This parameter only allows one address. Should a recipient choose to reply to the email, this will be the email address that reply will come back to.

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject'
```

By default, using an email address will simply show the email address in the recipient’s _FROM_ field. However, if you’d like to specify a name or some kind of label like _Service Account Mailbox_, you may also specify a name and an email like:

```powershell
Adam Bertram <adbertram@gmail.com>
```

> _Notice that the `Subject` parameter was used. This parameter is always required. You’ll see this parameter used in all examples._

## Body

The `Body` parameter allows you to specify what will be in the email body. At the most simplest, you can specify any text you’d like and the cmdlet will send it via plaintext.

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body'
```

### Sending HTML Body Emails

You can also send an email body via HTML rather than plaintext. To do that, use the same `Body` parameter as you would with plaintext but use HTML for the string and use the `BodyAsHtml` switch parameter.

```powershell
$body = @'
<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>
'@

PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body $body -BodyAsHtml
```

> _Notice in the above example, I enclosed the body string in `@'` and `'@`. This is called a [here string](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2&viewFallbackFrom=powershell-6#here-strings). This allows you to define long strings typically seen in email bodies that contain carriage returns. Here strings preserve formatting of strings and is a great way to define the email body especially if it’s in HTML._

### Encoding

If you have special characters in the subject or body of your email, you can use the `Encoding` parameter. This parameter allows you to encode the email subject and body via the specified encoding type before sending.

You have a few options here:

*   ASCII (default)
*   UTF8
*   UTF7
*   UTF32
*   Unicode
*   BigEndianUnicode
*   Default
*   OEM

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -Encoding UTF8
```

### Attachments

The cmdlet can also attach one or more files. To do so, you can use the `Attachments` parameter and provide the path to the file(s) you’d like to attach.

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -Attachments 'C:\file.doc'
```

You can also specify multiple attachments via a collection by separating them with a comma.

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -Attachments 'C:\file.doc','D:\report.xlsx'
```

The `Attachments` parameter also allows you to pipe files via cmdlets like `Get-Item` and `Get-ChildItem` to the `Send-MailMessage` cmdlet as well.

```powershell
PS51> Get-ChildItem -Path 'C:\MyFiles' | Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body'
```

## Secure and Authenticated Email

By default, the cmdlet sends email via unencrypted SMTP communication over port 25. However, it also has support for sending encrypted email via SSL/TLS with a username and password.

If you attempt to relay email through an SMTP server that requires authentication, the command fails with an error message like below.

```powershell
The SMTP server requires a secure connection or the client was not
authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.
```

To remedy this, you must first specify the port (typically 587 for TLS) and the `UseSsl` parameter. This tells the cmdlet to attempt to connect to port 587 on the SMTP Server and encrypt the entire message. You will typically (always?) also need to specify the username/password to authenticate to the SMTP server by using the `Credential` parameter.

```powershell
PS51> $credential = Get-Credential
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -UseSsl -Port 587 -Credential $credential
```

> _Above I’m grabbing a credential (PSCredential) object using the `Get-Credential` cmdlet. This sometimes poses a problem because it’s interactive meaning it stops the script to ask for a username and password. To prevent this, you could [create a PSCredential object on the fly](https://adamtheautomator.com/powershell-get-credential/)._

A common email example is to use Gmail. Using the knowledge you’ve gained above, you can now easily send email through Gmail using the smtp.gmail.com SMTP server as shown below.

```powershell
$gmailCred = Get-Credential

$sendMailParams = @{
    From = 'adbertram@gmail.com' ## Must be gmail.com
    To = 'someemail@domain.com'
    Subject = 'some subject'
    Body = 'some body'
    SMTPServer = 'smtp.gmail.com'
    SMTPPort = 587
    UseSsl = $true
    Credential = $gmailCred
}

Send-MailMessage @sendMailParams
```

## Assigning Email Priority

Although one feature of email I personally wish would die, you can assign priority levels to the emails you send via the `Priority` parameter. This priority is then interpreted in various ways by the email client.

![High priority message in Outlook](https://adamtheautomator.com/content/images/2019/08/00_lead_image_important_message.png.pagespeed.ce.XzlmA5p1Xo.png)

High priority message in Outlook

Send-mailmessage allows you to assign an email with three different priorities.

*   Normal (default)
*   High
*   Low

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -Priority High
```

But please, for the love of God, don’t think all of your emails are high priority!

## Delivery Notifications

Finally, you can specify [delivery notifications](https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.sendmailmessage.deliverynotificationoption?view=pscore-6.2.0) for emails. Delivery notifications are what’s typically known as read receipts in some email clients. Delivery notifications allow you to be notified if/when the email is received by the recipient. However, the recipient must still allow it.

You have four options when requesting delivery notifications.

*   None (default)
*   OnSuccess (when the email is delivery is successful)
*   OnFailure (notify if the delivery is unsuccessful)
*   Delay (when the email is delayed via an SMTP server)

You can specify a delivery notification option by using the `DeliveryNotificationOptions` parameter.

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -DeliveryNotificationsOptions 'OnSuccess'
```

You can also request multiple delivery notifications at once by separating them with a comma.

```powershell
PS51> Send-MailMessage -From me@company.org -To joe@gmail.com -Subject 'this is a subject' -Body 'this is the body' -DeliveryNotificationsOptions 'OnSuccess','OnFailure','Delay'
```

## Summary

In this post, you learned all about the Send-mailmessage cmdlet and what it can. We covered this cmdlet extensively using every parameter it has along with examples. I hope this post can server as a reference for you when using the Send-mailmessage cmdlet.

## Further Reading

Be sure to check out some other related posts!

*   [Using the `Get-ChildItem` PowerShell cmdlet](https://adamtheautomator.com/get-childitem/)
*   [Using the `Set-Content` PowerShell cmdlet](https://adamtheautomator.com/powershell-write-to-file/)
*   [Using the `Out-File` PowerShell cmdlet](https://adamtheautomator.com/out-file/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fsend-mailmessage%2F&text=Send%20Emails%20Effortlessly%20with%20Send-MailMessage%20PowerShell%20Cmdlet)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fsend-mailmessage%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fsend-mailmessage%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
