---
title: "Set-DbaDbMailAccount"
description: "Modifies an existing Database Mail account on SQL Server"
url: "https://dbatools.io/Set-DbaDbMailAccount/"
availability: "Windows, Linux, macOS"
tags: ["DatabaseMail", "DbMail", "Mail"]
author: "the dbatools team + Claude"
source: "https://github.com/dataplat/dbatools/blob/master/public/Set-DbaDbMailAccount.ps1"
last_updated: "2024-01-01"
---

# Set-DbaDbMailAccount

## Synopsis

Modifies an existing Database Mail account on SQL Server

## Description

Modifies the configuration of an existing Database Mail account including account properties (display name, email address, description) and mail server settings (SMTP server name, port, SSL, and authentication). This command is useful for updating Database Mail accounts to use cloud email services like Office 365 or Gmail, or for updating credentials when passwords change.

## Syntax

```powershell
Set-DbaDbMailAccount
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Account] <String[]>]
    [[-InputObject] <MailAccount[]>]
    [[-DisplayName] <String>]
    [[-Description] <String>]
    [[-EmailAddress] <String>]
    [[-ReplyToAddress] <String>]
    [[-NewMailServerName] <String>]
    [[-Port] <Int32>]
    [-EnableSSL]
    [-UseDefaultCredentials]
    [[-UserName] <String>]
    [[-Password] <SecureString>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Updates the MaintenanceAlerts mail account on sql2017 to use port 587 with SSL enabled

```powershell
PS C:\> Set-DbaDbMailAccount -SqlInstance sql2017 -Account 'MaintenanceAlerts' -Port 587 -EnableSSL
```

### Example 2: Migrates the Alerts mail account on sql2017 to Office 365 with SSL and basic authentication

```powershell
PS C:\> $splatAccount = @{
>>     SqlInstance       = 'sql2017'
>>     Account           = 'Alerts'
>>     NewMailServerName = 'smtp.office365.com'
>>     Port              = 587
>>     EnableSSL         = $true
>>     UserName          = 'alerts@company.com'
>>     Password          = (ConvertTo-SecureString 'app-password' -AsPlainText -Force)
>> }
PS C:\> Set-DbaDbMailAccount @splatAccount
```

### Example 3: Uses the pipeline to update the MaintenanceAlerts account to use port 25 with SSL disabled

```powershell
PS C:\> Get-DbaDbMailAccount -SqlInstance sql2017 -Account 'MaintenanceAlerts' | Set-DbaDbMailAccount -Port 25 -EnableSSL:$false
```

### Example 4: Configures the DomainRelay mail account to use Windows integrated authentication

```powershell
PS C:\> Set-DbaDbMailAccount -SqlInstance sql2017 -Account 'DomainRelay' -UseDefaultCredentials
```

### Optional Parameters

##### -SqlInstance

The target SQL Server instance or instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).  
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.  
For MFA support, please use Connect-DbaInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Account

Specifies one or more Database Mail account names to modify. Used in combination with -SqlInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -InputObject

Accepts MailAccount objects from the pipeline, typically from Get-DbaDbMailAccount. Allows you to chain Database Mail commands together.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value |  |

##### -DisplayName

Updates the friendly name that appears in the 'From' field of outgoing emails.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Description

Updates the optional documentation text describing the account's purpose and usage.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EmailAddress

Updates the sender email address that appears in outgoing messages from this Database Mail account.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -ReplyToAddress

Updates the alternate email address for replies when different from the sender address.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -NewMailServerName

Renames or replaces the SMTP server hostname for the mail account. Use this to migrate to a different SMTP server.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Port

Updates the TCP port number used to connect to the SMTP server. Common values are 25 (standard SMTP), 465 (SMTPS), and 587 (SMTP with STARTTLS).  
Use 587 for Office 365 and Gmail which require STARTTLS.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | 0 |

##### -EnableSSL

Enables or disables SSL/TLS encryption for the SMTP connection. Use -EnableSSL:$false to explicitly disable SSL.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -UseDefaultCredentials

Enables or disables Windows integrated authentication (the SQL Server service account credentials) for SMTP authentication.  
Use -UseDefaultCredentials:$false to explicitly disable Windows authentication.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -UserName

Updates the username for SMTP authentication. For Office 365, use the full email address.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Password

Updates the password for SMTP authentication as a SecureString.  
Create with: ConvertTo-SecureString 'yourpassword' -AsPlainText -Force

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.  
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.  
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**Microsoft.SqlServer.Management.Smo.Mail.MailAccount**

Returns the updated MailAccount object from the specified SQL Server instance.

**Default display properties (via Select-DefaultView):**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- Id: Unique identifier for the mail account
- Name: Name of the mail account
- DisplayName: Friendly name that appears in the 'From' field of emails
- Description: Description of the account's purpose
- EmailAddress: Sender email address for outgoing messages
- ReplyToAddress: Alternate email address for replies
- IsBusyAccount: Boolean indicating if the account is currently processing emails
- MailServers: Collection of mail servers associated with this account

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
