{"id":9840,"date":"2020-09-12T08:29:20","date_gmt":"2020-09-11T22:29:20","guid":{"rendered":"https:\/\/database.guide\/?p=9840"},"modified":"2020-09-12T08:29:23","modified_gmt":"2020-09-11T22:29:23","slug":"update-a-database-mail-account-in-sql-server-t-sql","status":"publish","type":"post","link":"https:\/\/database.guide\/update-a-database-mail-account-in-sql-server-t-sql\/","title":{"rendered":"Update a Database Mail Account in SQL Server (T-SQL)"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/database.guide\/what-is-sql-server\/\" title=\"What is SQL Server?\">SQL Server<\/a>, you can use the <code>sysmail_update_account_sp<\/code> stored procedure in the <code>msdb<\/code> database to update your existing Database Mail accounts with <a href=\"https:\/\/database.guide\/what-is-t-sql\/\" title=\"What is T-SQL?\">T-SQL<\/a>. <\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Update the Account Details<\/h2>\n\n\n\n<p>You can update an account&#8217;s details based on its name.<\/p>\n\n\n\n<p>That is, if you don&#8217;t need to change the account name, you don&#8217;t need to provide the account ID &#8211; as long as you provide the name.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EXECUTE msdb.dbo.sysmail_update_account_sp  \n    @account_name = 'DB Admin',  \n    @description = 'Mail account for admin emails.',  \n    @email_address = 'admin@example.com',  \n    @replyto_address = 'reply@example.com',  \n    @display_name = 'DB Automated Mailer',  \n    @mailserver_name = 'smtp.example.com',\n    @port = 25;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Update the Account Name<\/h2>\n\n\n\n<p>When both the account name and the account ID are specified, the stored procedure changes the account name in addition to updating the information for the account.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EXECUTE msdb.dbo.sysmail_update_account_sp\n    @account_id = 1,\n    @account_name = 'Updated DB Admin',  \n    @description = 'Mail account for admin emails.',  \n    @email_address = 'admin@example.com',  \n    @replyto_address = 'reply@example.com',  \n    @display_name = 'DB Automated Mailer',  \n    @mailserver_name = 'smtp.example.com',\n    @port = 25;<\/code><\/pre>\n\n\n\n<p>In this example I updated the name and various other details of the account. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Syntax<\/h2>\n\n\n\n<p>The official syntax goes like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sysmail_update_account_sp &#91; &#91; @account_id = ] account_id ] &#91; , ] &#91; &#91; @account_name = ] 'account_name' ] ,  \n    &#91; @email_address = ] 'email_address' ,   \n    &#91; @display_name = ] 'display_name' ,   \n    &#91; @replyto_address = ] 'replyto_address' ,  \n    &#91; @description = ] 'description' ,   \n    &#91; @mailserver_name = ] 'server_name' ,   \n    &#91; @mailserver_type = ] 'server_type' ,   \n    &#91; @port = ] port_number ,   \n    &#91; @timeout = ] 'timeout' ,  \n    &#91; @username = ] 'username' ,  \n    &#91; @password = ] 'password' ,  \n    &#91; @use_default_credentials = ] use_default_credentials ,  \n    &#91; @enable_ssl = ] enable_ssl<\/code><\/pre>\n\n\n\n<p>See the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/system-stored-procedures\/sysmail-update-account-sp-transact-sql\" target=\"_blank\" rel=\"noreferrer noopener\">Microsoft documentation<\/a> for a detailed explanation of each argument. <\/p>\n\n\n\n<p>Note that the <code>sysmail_update_account_sp<\/code> stored procedure is in the <code>msdb<\/code> database, and it&#8217;s owned by the <code>dbo<\/code> schema. Therefore, you&#8217;ll need to use three part naming if you execute it from outside the <code>msdb<\/code> database.<\/p>\n\n\n\n<p>You can also use the <code>sysmail_add_account_sp<\/code> stored procedure to <a href=\"https:\/\/database.guide\/create-a-database-mail-account-in-sql-server-t-sql\/\" title=\"Create a Database Mail Account in SQL Server (T-SQL)\">create a new Database Mail account<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In SQL Server, you can use the sysmail_update_account_sp stored procedure in the msdb database to update your existing Database Mail accounts with T-SQL.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[10,77,104,61],"class_list":["post-9840","post","type-post","status-publish","format-standard","hentry","category-sql-server","tag-how-to","tag-mssql","tag-send-email","tag-t-sql"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=9840"}],"version-history":[{"count":4,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9840\/revisions"}],"predecessor-version":[{"id":9941,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/9840\/revisions\/9941"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=9840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=9840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=9840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}