{"id":10971,"date":"2020-11-13T09:38:07","date_gmt":"2020-11-12T23:38:07","guid":{"rendered":"https:\/\/database.guide\/?p=10971"},"modified":"2020-11-13T10:00:15","modified_gmt":"2020-11-13T00:00:15","slug":"how-to-setup-database-mail-in-sql-server-ssms","status":"publish","type":"post","link":"https:\/\/database.guide\/how-to-setup-database-mail-in-sql-server-ssms\/","title":{"rendered":"How to Setup Database Mail in SQL Server (SSMS)"},"content":{"rendered":"\n<p>This article shows you how to setup Database Mail for the first time on a new SQL Server installation.<\/p>\n\n\n\n<p>As with many things SQL Server, you can configure Database Mail via the <a href=\"https:\/\/database.guide\/what-is-sql-server-management-studio\/\" title=\"What Is SQL Server Management Studio?\">SSMS<\/a> GUI, or you can do it using <a href=\"https:\/\/database.guide\/what-is-t-sql\/\" title=\"What is T-SQL?\">T-SQL<\/a> code.<\/p>\n\n\n\n<p>This article covers the SSMS GUI option. If you&#8217;re interested in the T-SQL option, see <a href=\"https:\/\/database.guide\/how-to-send-emails-from-sql-server-t-sql\/\" title=\"How to Send Emails from SQL Server (T-SQL)\">How to Send Email in SQL Server (T-SQL)<\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Configure Database Mail<\/h2>\n\n\n\n<p>The SSMS GUI gives us a nice, friendly wizard that walks us through the process of configuring Database Mail.<\/p>\n\n\n\n<p>To start the wizard, use the Object Explorer to expand the <strong>Management<\/strong> node. Under this node, you should see the <strong>Database Mail<\/strong> option.<\/p>\n\n\n\n<p>Right-click <strong>Database Mail<\/strong> to bring up the context menu:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_1.png\" alt=\"Screenshot of the Configure Database Mail option\" class=\"wp-image-10972\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_1.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_1-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_1-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Click <strong>Configure Database<\/strong> Mail from the context menu.<\/p>\n\n\n\n<p>This opens a Welcome screen (unless you&#8217;ve previously done this and selected the &#8220;Skip this page in the future&#8221; option):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_2.png\" alt=\"Screenshot of the Welcome screen\" class=\"wp-image-10973\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_2.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_2-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_2-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Click <strong>Next<\/strong>.<\/p>\n\n\n\n<p>This brings you to the following window, where you choose what you want to do next:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_3.png\" alt=\"Screenshot of the Select Configuration Task screen\" class=\"wp-image-10974\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_3.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_3-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_3-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Leave the first option selected and click <strong>Next<\/strong>.<\/p>\n\n\n\n<p>You may get the following prompt, asking if you&#8217;d like to enable Database Mail:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_4.png\" alt=\"Screenshot of the dialog box asking to confirm that you want to enable Database Mail\" class=\"wp-image-10975\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_4.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_4-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_4-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Click <strong>Yes<\/strong>.<\/p>\n\n\n\n<p>The reason for this dialog box is that, by default, Database Mail is not enabled on a fresh SQL Server install. If you want to use Database Mail, you need to enable it the first time you configure it. <\/p>\n\n\n\n<p>Therefore, you won&#8217;t see this dialog box on any subsequent visits to the Database Mail configuration wizard (unless you&#8217;re re-enabling Database Mail after having disabled it).  <\/p>\n\n\n\n<p>Anyway, we should now be on the New Profile screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_5.png\" alt=\"Screenshot of the New Profile dialog box\" class=\"wp-image-10976\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_5.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_5-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_5-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>The way Database Mail works is, you create one or more profiles, and then add one or more accounts into those profiles.<\/p>\n\n\n\n<p>This screen allows you to do both.<\/p>\n\n\n\n<p>So go ahead and enter your profile details at the top, as well as a description, then click <strong>Add&#8230;<\/strong>. <\/p>\n\n\n\n<p>This will bring you to the New Account screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_6.png\" alt=\"Screenshot of the New Database Mail Account dialog box\" class=\"wp-image-10979\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_6.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_6-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_6-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Enter account details as required. You&#8217;ll need to specify an outgoing mail server that works, and that you can authenticate against if required. Be sure to use the correct port. Common ports are 25, 465, and 587. <\/p>\n\n\n\n<p>Click <strong>OK<\/strong> once you&#8217;ve entered the details.<\/p>\n\n\n\n<p>This returns you to the Profile screen, except that it&#8217;s now called Manage Existing Profile instead of New Profile:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_7.png\" alt=\"Screenshot of the Manage Existing Profile screen\" class=\"wp-image-10982\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_7.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_7-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_7-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>You&#8217;ll see your mail account in the list of SMTP accounts. You can add more accounts if required. <\/p>\n\n\n\n<p>One of the benefits of profiles is that, when mail is sent, if one account fails for whatever reason, Database Mail will try the next one listed in the profile, and if that account&#8217;s no good, the next one, and so on.<\/p>\n\n\n\n<p>But for now, click <strong>Next &gt;<\/strong>.<\/p>\n\n\n\n<p>That brings us to the Manage Profile Security screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_8.png\" alt=\"Screenshot of the Manage Profile Security screen\" class=\"wp-image-10981\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_8.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_8-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_8-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>In my example I selected Public and Yes in order to make it a the default public profile.<\/p>\n\n\n\n<p>However, whether you select this option will depend on your circumstances.<\/p>\n\n\n\n<p>A public profile allows any user with access to the&nbsp;<strong>msdb<\/strong>&nbsp;database to send e-mail using that profile. A private profile can be used by a user or by a role.&nbsp;<\/p>\n\n\n\n<p>Making this the default profile means that, if someone tries to send mail without specifying which profile to use, this profile will be used. However, it will first try to use the default <em>private<\/em> profile for the current user. If the user does not have a default private profile, it will use the default public profile.<\/p>\n\n\n\n<p>So basically, what we did here was elect this profile to be the backup profile to the backup profile.<\/p>\n\n\n\n<p>Anyway, once you&#8217;ve done whatever you needed to do at this screen (if anything) click <strong>Next &gt;<\/strong>.<\/p>\n\n\n\n<p>Now we get the Configure System Parameters screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_9.png\" alt=\"Screenshot of the Configure System Parameters screen\" class=\"wp-image-10983\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_9.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_9-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_9-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Most of these parameters are reasonably self explanatory. Feel free to change anything you need changed, then click <strong>Next &gt;<\/strong>..<\/p>\n\n\n\n<p>Almost done &#8211; it&#8217;s the Complete the Wizard screen:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_10.png\" alt=\"Screenshot of the Complete the Wizard screen\" class=\"wp-image-10984\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_10.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_10-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_10-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>If it all looks good, click <strong>Finish<\/strong>.<\/p>\n\n\n\n<p>The wizard finally goes ahead and actually does the configuration. It will go through each step and return its status: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_11.png\" alt=\"Screenshot of the Configuring... screen\" class=\"wp-image-10985\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_11.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_11-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_11-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Hopefully you&#8217;ll see &#8220;Success&#8221; written all over it like we see here. <\/p>\n\n\n\n<p>That completes the setup of Database Mail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Send a Test Email<\/h2>\n\n\n\n<p>At this stage, you&#8217;ll probably want to send yourself a test email, just to confirm that everything is working OK.<\/p>\n\n\n\n<p>You can do that back at the Object Explorer by right clicking on <strong>Database Mail<\/strong> and clicking <strong>Send Test E-mail&#8230;<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_12.png\" alt=\"Screenshot of the Send Test E-Mail... option in the Object Explorer\" class=\"wp-image-10986\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_12.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_12-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_12-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>This will launch a dialog box that you can use to enter the recipient email address, as well as a subject and body text (of which Database Mail pre-populates with sample text):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_13.png\" alt=\"Screenshot of the Sent Test E-Mail dialog box\" class=\"wp-image-10987\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_13.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_13-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_13-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Once you&#8217;ve entered a recipient and (optionally) the other details, click <strong>Send Test E-Mail<\/strong>.<\/p>\n\n\n\n<p>This results in the following dialog box:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_14.png\" alt=\"Screenshot of the confirmation box\" class=\"wp-image-10988\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_14.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_14-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_14-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Hopefully you will receive the email at the designated email address.<\/p>\n\n\n\n<p>Note that, just because we set up Database Mail, doesn&#8217;t mean that the mail will necessarily be sent. There could be any number of problems between Database Mail, the SMTP mail server, and the receiving mail server. For example, if you didn&#8217;t provide the correct authentication for the mail server, the mail won&#8217;t be sent.<\/p>\n\n\n\n<p>You can always take a look at the log file viewer, by right-clicking on Database Mail and selecting <strong>View Database Mail Log<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large screenshot\"><img loading=\"lazy\" decoding=\"async\" width=\"996\" height=\"706\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_15.png\" alt=\"Screenshot of the  View Database Mail Log option in the Object Explorer\" class=\"wp-image-10989\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_15.png 996w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_15-300x213.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2020\/11\/configure_database_mail_15-768x544.png 768w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/figure>\n\n\n\n<p>Other things you can do is run the following scripts: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/database.guide\/check-the-status-of-the-database-mail-queues-in-sql-server-t-sql\/\" title=\"Check the Status of the Database Mail Queues in SQL Server (T-SQL)\">Check the status of the mail queues<\/a><\/li><li><a href=\"https:\/\/database.guide\/check-how-many-mail-items-are-in-the-queue-in-database-mail-in-sql-server-t-sql\/\" title=\"Check How Many Mail Items are in the Queue in Database Mail in SQL Server (T-SQL)\">Check how many mail items are in the queue<\/a><\/li><li><a href=\"https:\/\/database.guide\/check-for-failed-email-in-sql-server-t-sql\/\" title=\"Check for Failed Email in SQL Server (T-SQL)\">See a list of failed emails<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Permissions<\/h2>\n\n\n\n<p>To configure Database Mail you must be a member of the&nbsp;<strong>sysadmin<\/strong>&nbsp;fixed server role. To send Database Mail you must be a member of the&nbsp;<strong>DatabaseMailUserRole<\/strong>&nbsp;database role in the&nbsp;<strong>msdb<\/strong>&nbsp;database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows you how to setup Database Mail for the first time on a new SQL Server installation. As with many things SQL Server, you can configure Database Mail via the SSMS GUI, or you can do it using T-SQL code. This article covers the SSMS GUI option. If you&#8217;re interested in the T-SQL &#8230; <a title=\"How to Setup Database Mail in SQL Server (SSMS)\" class=\"read-more\" href=\"https:\/\/database.guide\/how-to-setup-database-mail-in-sql-server-ssms\/\" aria-label=\"Read more about How to Setup Database Mail in SQL Server (SSMS)\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,5],"tags":[10,77,104],"class_list":["post-10971","post","type-post","status-publish","format-standard","hentry","category-database-tools","category-sql-server","tag-how-to","tag-mssql","tag-send-email"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/10971","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=10971"}],"version-history":[{"count":5,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/10971\/revisions"}],"predecessor-version":[{"id":10994,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/10971\/revisions\/10994"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=10971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=10971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=10971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}