{"id":7,"date":"2017-08-01T20:52:23","date_gmt":"2017-08-01T20:52:23","guid":{"rendered":"http:\/\/www.spk.com\/?p=7"},"modified":"2017-08-01T20:54:09","modified_gmt":"2017-08-01T20:54:09","slug":"sql-server-configuring-troubleshooting-database-mail","status":"publish","type":"post","link":"https:\/\/www.spktechfit.com\/?p=7","title":{"rendered":"SQL Server: Configuring &#038; Troubleshooting Database Mail"},"content":{"rendered":"<p>Database mail is great tool which allows you to send notification emails from your SQL Server. You can use to send notifications for things like backups, error, resource alerts etc&#8230;<\/p>\n<h2>Configuring Database Mail<\/h2>\n<p><b>Using the SSMS Wizard<\/b><\/p>\n<ol>\n<li data-aria-posinset=\"1\" data-aria-level=\"2\">Go to Management -&gt; Right Click on &#8216;Database Mail&#8217; and select &#8216;Configure Database Mail&#8217;<\/li>\n<li data-aria-posinset=\"2\" data-aria-level=\"2\">Select the first option &#8216;Setup Database Mail by performing the following tasks<\/li>\n<li data-aria-posinset=\"3\" data-aria-level=\"2\">Give the Profile a name. The profile is a container for the email accounts. You can have multiple email accounts for a profile.<\/li>\n<li data-aria-posinset=\"4\" data-aria-level=\"2\">Click on the Add button in the SMTP Accounts section<\/li>\n<li data-aria-posinset=\"5\" data-aria-level=\"2\">Enter the details for your email account. I used my\u00a0gmail\u00a0account. You might need to check with your email provider for the settings for your account<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9\" src=\"http:\/\/www.spk.com\/wp-content\/uploads\/2017\/08\/ConfigureMail.jpg\" alt=\"\" width=\"643\" height=\"538\" \/><\/li>\n<li data-aria-posinset=\"7\" data-aria-level=\"2\">Click Ok. You can add multiple accounts if you want. It will try the email accounts by the\u00a0priority\u00a0that they are set to.<\/li>\n<li data-aria-posinset=\"7\" data-aria-level=\"2\">On the Security page you can set it as a public or private profile. Public means the profile can be used by all users of the database. I set it as Public.<\/li>\n<li data-aria-posinset=\"7\" data-aria-level=\"2\">On the System Parameter page you can configure some more advanced settings if you want. Things like retry attempts, max file size etc&#8230; I left it as the default<\/li>\n<li data-aria-posinset=\"7\" data-aria-level=\"2\">Click Next, then Finish and it should configure without any errors<\/li>\n<\/ol>\n<p>Test your configuration by right clicking on Database Mail and selecting &#8216;Send a Test email&#8217;. Enter your email address to test. If it doesn\u2019t work, see the Troubleshooting section<\/p>\n<p>&nbsp;<\/p>\n<p><b>Using T-SQL:<\/b><\/p>\n<p><b>&#8211;Add mail account<\/b><\/p>\n<p>EXEC\u00a0msdb.dbo.sysmail_add_account_sp<\/p>\n<p>@account_name\u00a0= &#8216;Gmail&#8217;,<\/p>\n<p>@email_address\u00a0= &#8216;<a href=\"mailto:keenaghan.sean@gmail.com\">keenaghan.sean@gmail.com<\/a>&#8216;,<\/p>\n<p>@mailserver_name\u00a0= &#8216;smtp.gmail.com&#8217;,<\/p>\n<p>@port = 587,<\/p>\n<p>@enable_ssl\u00a0= 1,<\/p>\n<p>@username = &#8216;<a href=\"mailto:keenaghan.sean@gmail.com\">keenaghan.sean@gmail.com<\/a>&#8216;,<\/p>\n<p>@password = &#8216;******&#8217;<\/p>\n<p><b>&#8211;Add mail profile, storing new ID in output\u00a0parameters<\/b><\/p>\n<p>DECLARE @profID\u00a0int<\/p>\n<p>EXEC\u00a0msdb.dbo.sysmail_add_profile_sp<\/p>\n<p>@profile_name\u00a0= &#8216;SQL Emails&#8217;,<\/p>\n<p>@description = &#8216;Profile used for administrative mail.&#8217;,<\/p>\n<p>@profile_id\u00a0= @profID\u00a0OUTPUT<\/p>\n<p><b>&#8211;Add mail account to profile, using @profID\u00a0from above<\/b><\/p>\n<p>EXEC\u00a0msdb.dbo.sysmail_add_profileaccount_sp<\/p>\n<p>@profile_id\u00a0= @profID,<\/p>\n<p>@account_name\u00a0= &#8216;Gmail&#8217;,<\/p>\n<p>@sequence_number\u00a0= 1<\/p>\n<p><b>&#8211;Test the configuration by sending an email<\/b><\/p>\n<p>EXEC\u00a0msdb.dbo.sp_send_dbmail<\/p>\n<p>@profile_name=&#8217;SQL Emails&#8217;,<\/p>\n<p>@recipients=&#8217;<a href=\"mailto:garth@nuggetlab.com\">keenaghan.sean@gmail.com<\/a>&#8216;,<\/p>\n<p>@subject=&#8217;Testing Emails&#8217;,<\/p>\n<p>@body=&#8217;If you\u00a0recieved\u00a0this email, it worked!&#8217;<\/p>\n<h2><\/h2>\n<h1><b>Troubleshooting Database Mail<\/b><\/h1>\n<h5>To check the Database Mail logs using SSMS:<\/h5>\n<ol>\n<li data-aria-posinset=\"1\" data-aria-level=\"2\">Go to SQL\u00a0Server Agent -&gt; Error Logs<\/li>\n<li data-aria-posinset=\"2\" data-aria-level=\"2\">Selected the required data range<\/li>\n<li data-aria-posinset=\"3\" data-aria-level=\"2\">Tick the &#8216;Database\u00a0Mail&#8217; checkbox in the &#8216;Select Logs&#8217; section on the left<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><b>To check the Database Mail logs using T-SQL:<\/b><br \/>\nThere is a system table which stores the Database mail logs. To view this table using T-SQL:<\/p>\n<p><i>SELECT * FROM\u00a0msdb.dbo.sysmail_log<br \/>\n<\/i><i>GO<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database mail is great tool which allows you to send notification emails from your SQL Server. You can use to send notifications for things like backups, error, resource alerts etc&#8230; Configuring Database Mail Using the SSMS Wizard Go to Management -&gt; Right Click on &#8216;Database Mail&#8217; and select &#8216;Configure Database Mail&#8217; Select the first option [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,3],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/7"}],"collection":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":2,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"predecessor-version":[{"id":10,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions\/10"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/media\/9"}],"wp:attachment":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}