Created
April 23, 2018 19:27
-
-
Save taddison/bad62ea292a395b1e86f967dd265f04f to your computer and use it in GitHub Desktop.
Configure DBMail with SendGrid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @mailFromDomain nvarchar(128) = N'@foo.com' | |
declare @username nvarchar(128) = 'apikey' | |
declare @password nvarchar(128) = 'SG.SECRETS'; | |
declare @port int = 587; | |
declare @server nvarchar(128) = 'smtp.sendgrid.com' | |
declare @replyTo nvarchar(128) = 'donotreply' + @mailFromDomain; | |
declare @serverName nvarchar(128) = substring(@@servername,8,100); | |
declare @emailAddress nvarchar(128) = @serverName + @mailFromDomain; | |
declare @displayName nvarchar(128) = @serverName; | |
declare @accountName nvarchar(128) = N'Default Mail Account - ' + @serverName; | |
declare @profileName nvarchar(128) = N'Default Mail Profile - ' + @serverName; | |
exec msdb.dbo.sysmail_add_account_sp | |
@Account_name = @accountName | |
,@description = N'Default mail account' | |
,@email_address = @emailAddress | |
,@replyto_address = @replyTo | |
,@display_name = @displayName | |
,@mailserver_name = @server | |
,@port = @port | |
,@username = @username | |
,@password = @password | |
exec msdb.dbo.sysmail_add_profile_sp | |
@profile_name = @profileName | |
,@description = 'Default mail profile' | |
exec msdb.dbo.sysmail_add_profileaccount_sp | |
@profile_name = @profileName | |
,@Account_name = @accountName | |
,@sequence_number=1 | |
exec msdb.dbo.sysmail_add_principalprofile_sp | |
@profile_name = @profileName | |
,@principal_name = 'guest' | |
,@is_default = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that if your SendGrid API Key is SG.ABCD1234, you would set the parameters as follows:
The username is always just
apikey
.