forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 2
SqlDatabaseMail
johlju edited this page Jun 19, 2020
·
1 revision
Parameter | Attribute | DataType | Description | Allowed Values |
---|---|---|---|---|
AccountName | Key | String | The name of the Database Mail account. | |
InstanceName | Key | String | The name of the SQL instance to be configured. | |
EmailAddress | Required | String | The e-mail address from which mail will originate. | |
MailServerName | Required | String | The fully qualified domain name 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. When set to 'Present', the Database Mail will be created. When set to 'Absent', the Database Mail will be removed. Default value is 'Present'. | Present, Absent |
ServerName | Write | String | The hostname of the SQL Server to be configured. Default value is $env:COMPUTERNAME. | |
DisplayName | Write | String | The display name of the originating email address. Default value is the same value assigned to the EmailAddress parameter. | |
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. |
The SqlDatabaseMail
DSC resource manages SQL Server Database Mail.
Note: 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
}
}
}
- SqlAG
- SqlAGDatabase
- SqlAgentAlert
- SqlAgentFailsafe
- SqlAgentOperator
- SqlAGListener
- SqlAGReplica
- SqlAlias
- SqlAlwaysOnService
- SqlConfiguration
- SqlDatabase
- SqlDatabaseDefaultLocation
- SqlDatabaseMail
- SqlDatabaseObjectPermission
- SqlDatabaseOwner
- SqlDatabasePermission
- SqlDatabaseRecoveryModel
- SqlDatabaseRole
- SqlDatabaseUser
- SqlEndpoint
- SqlEndpointPermission
- SqlLogin
- SqlMaxDop
- SqlMemory
- SqlPermission
- SqlProtocol
- SqlProtocolTcpIp
- SqlReplication
- SqlRole
- SqlRS
- SqlRSSetup
- SqlScript
- SqlScriptQuery
- SqlSecureConnection
- SqlServerConfiguration
- SqlServerDatabaseMail
- SqlServerEndpoint
- SqlServerEndpointPermission
- SqlServerEndpointState
- SqlServerLogin
- SqlServerMaxDop
- SqlServerMemory
- SqlServerNetwork
- SqlServerPermission
- SqlServerProtocol
- SqlServerProtocolTcpIp
- SqlServerReplication
- SqlServerRole
- SqlServerSecureConnection
- SqlServiceAccount
- SqlSetup
- SqlWaitForAG
- SqlWindowsFirewall