Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Configure DBMail with SendGrid
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
You can’t perform that action at this time.