-
Notifications
You must be signed in to change notification settings - Fork 225
SqlDatabaseMail
dscbot edited this page Oct 26, 2024
·
13 revisions
Parameter | Attribute | DataType | Description | Allowed Values |
---|---|---|---|---|
AccountName | Key | String | The name of the Database Mail account. | |
InstanceName | Key | String | The name of the SQL Server instance to be configured. | |
EmailAddress | Required | String | The e-mail address from which mail will originate. | |
MailServerName | Required | String | The fully qualified domain name (FQDN) of the mail server name to which e-mail are sent. | |
ProfileName | Required | String | The name of the Database Mail profile. | |
Ensure | Write | String | Specifies the desired state of the Database Mail account. When set to 'Present' the Database Mail account will be created. When set to 'Absent' the Database Mail account will be removed. Default value is 'Present' . |
Present , Absent
|
ServerName | Write | String | The hostname of the SQL Server to be configured. Default value is the current computer name. | |
DisplayName | Write | String | The display name of the originating email address. Default value is the same value assigned to the parameter EmailAddress. | |
ReplyToAddress | Write | String | The e-mail address to which the receiver of e-mails will reply to. Default value is the same e-mail address assigned to parameter EmailAddress. | |
Description | Write | String | The description for the Database Mail profile and account. | |
LoggingLevel | Write | String | The logging level that the Database Mail will use. If not specified the default logging level is 'Extended' . |
Normal , Extended , Verbose
|
TcpPort | Write | UInt16 | The TCP port used for communication. Default value is port 25 . |
|
UseDefaultCredentials | Write | Boolean | Specifies if the DatabaseEngine credentials are used for SMTP server authentication. |
The SqlDatabaseMail
DSC resource manages SQL Server Database Mail.
Tip
Database Mail XPs can be enabled using the resource SqlConfiguration
.
- Target machine must be running Windows Server 2012 or later.
- Target machine must be running SQL Server Database Engine 2012 or later.
- Target machine must be running SQL Server Agent.
- Target machine must have enabled Database Mail XPs.
All issues are not listed here, see here for all open issues.
This example will enable Database Mail on a SQL Server instance and create a mail account with a default public profile.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$SqlInstallCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
node localhost
{
SqlConfiguration 'EnableDatabaseMailXPs'
{
ServerName = $Node.NodeName
InstanceName = 'DSCSQLTEST'
OptionName = 'Database Mail XPs'
OptionValue = 1
RestartService = $false
}
SqlDatabaseMail 'EnableDatabaseMail'
{
Ensure = 'Present'
ServerName = $Node.NodeName
InstanceName = 'DSCSQLTEST'
AccountName = 'MyMail'
ProfileName = 'MyMailProfile'
EmailAddress = '[email protected]'
ReplyToAddress = '[email protected]'
DisplayName = 'mail.company.local'
MailServerName = 'mail.company.local'
Description = 'Default mail account and profile.'
LoggingLevel = 'Normal'
TcpPort = 25
PsDscRunAsCredential = $SqlInstallCredential
}
}
}
This example will remove the mail profile and the mail account and disable Database Mail on a SQL Server instance.
Configuration Example
{
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$SqlInstallCredential
)
Import-DscResource -ModuleName 'SqlServerDsc'
node localhost {
SqlDatabaseMail 'DisableDatabaseMail'
{
Ensure = 'Absent'
ServerName = $Node.NodeName
InstanceName = 'DSCSQLTEST'
AccountName = 'MyMail'
ProfileName = 'MyMailProfile'
EmailAddress = '[email protected]'
MailServerName = 'mail.company.local'
PsDscRunAsCredential = $SqlInstallCredential
}
<#
Don't disable the Database Mail XPs if there are still mail accounts
left configured.
#>
SqlConfiguration 'DisableDatabaseMailXPs'
{
ServerName = $Node.NodeName
InstanceName = 'DSCSQLTEST'
OptionName = 'Database Mail XPs'
OptionValue = 0
RestartService = $false
}
}
}
- Add-SqlDscNode
- Add-SqlDscTraceFlag
- Complete-SqlDscFailoverCluster
- Complete-SqlDscImage
- Connect-SqlDscDatabaseEngine
- ConvertFrom-SqlDscDatabasePermission
- ConvertFrom-SqlDscServerPermission
- ConvertTo-SqlDscDatabasePermission
- ConvertTo-SqlDscServerPermission
- Disable-SqlDscAudit
- Disconnect-SqlDscDatabaseEngine
- Enable-SqlDscAudit
- Get-SqlDscAudit
- Get-SqlDscConfigurationOption
- Get-SqlDscDatabasePermission
- Get-SqlDscManagedComputer
- Get-SqlDscManagedComputerService
- Get-SqlDscPreferredModule
- Get-SqlDscServerPermission
- Get-SqlDscStartupParameter
- Get-SqlDscTraceFlag
- Import-SqlDscPreferredModule
- Initialize-SqlDscRebuildDatabase
- Install-SqlDscServer
- Invoke-SqlDscQuery
- New-SqlDscAudit
- Remove-SqlDscAudit
- Remove-SqlDscNode
- Remove-SqlDscTraceFlag
- Repair-SqlDscServer
- Save-SqlDscSqlServerMediaFile
- Set-SqlDscAudit
- Set-SqlDscDatabasePermission
- Set-SqlDscServerPermission
- Set-SqlDscStartupParameter
- Set-SqlDscTraceFlag
- Test-SqlDscIsDatabasePrincipal
- Test-SqlDscIsLogin
- Test-SqlDscIsSupportedFeature
- Uninstall-SqlDscServer
- SqlAG
- SqlAGDatabase
- SqlAgentAlert
- SqlAgentFailsafe
- SqlAgentOperator
- SqlAGListener
- SqlAGReplica
- SqlAlias
- SqlAlwaysOnService
- SqlAudit
- SqlConfiguration
- SqlDatabase
- SqlDatabaseDefaultLocation
- SqlDatabaseMail
- SqlDatabaseObjectPermission
- SqlDatabasePermission
- SqlDatabaseRole
- SqlDatabaseUser
- SqlEndpoint
- SqlEndpointPermission
- SqlLogin
- SqlMaxDop
- SqlMemory
- SqlPermission
- SqlProtocol
- SqlProtocolTcpIp
- SqlReplication
- SqlRole
- SqlRS
- SqlRSSetup
- SqlScript
- SqlScriptQuery
- SqlSecureConnection
- SqlServiceAccount
- SqlSetup
- SqlTraceFlag
- SqlWaitForAG
- SqlWindowsFirewall