title: SQL Server 2014 DB Mail Not Sending
body: <p>I'm on SQL Server 2014 and having a blast... my DB Mail isn't sending and I'm running out of places to look. I double checked the SQL account permissions to the DBmail executable - it has read and execute. I tried another mail account and profile with the same unsent issues.</p>
  
  <p>I'm running below queries as described here</p>
  
  <p><strong>Step # 1</strong></p>
  
  <p>Checking rights of dbowner</p>
  
  <p><a href="https://i.stack.imgur.com/Wk0JC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wk0JC.png" alt="enter image description here"></a></p>
  
  <p><strong>Setup # 2</strong></p>
  
  <pre><code>USE MASTER
  GO
  
  SP_CONFIGURE 'show advanced options', 1
  RECONFIGURE WITH OVERRIDE
  GO
  
  SP_CONFIGURE 'Database Mail XPs', 1
  RECONFIGURE WITH OVERRIDE
  GO
  
  SP_CONFIGURE 'show advanced options', 0
  RECONFIGURE WITH OVERRIDE
  GO
  </code></pre>
  
  <p>and above query successfully run without any error's</p>
  
  <p><a href="https://i.stack.imgur.com/CXOFQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CXOFQ.png" alt="enter image description here"></a></p>
  
  <p><strong>Step # 3</strong></p>
  
  <p>Configure Database Mail by using below query</p>
  
  <pre><code>EXECUTE msdb.dbo.sysmail_add_profile_sp  
      @profile_name = 'P2PEmailNotifications',  
      @description = 'Profile used for sending outgoing notifications using Gmail.' ;  
  GO
  
  EXECUTE msdb.dbo.sysmail_add_principalprofile_sp  
      @profile_name = 'P2PEmailNotifications',  
      @principal_name = 'public',  
      @is_default = 1 ;
  GO
  
  EXECUTE msdb.dbo.sysmail_add_account_sp  
      @account_name = 'MyGmail',  
      @description = 'Mail account for sending outgoing notifications.',  
      @email_address = 'MyGmailSMTPEMAIL@gmail.com',  
      @display_name = 'no-reply@ubl.com.pk',  
      @mailserver_name = 'smtp.gmail.com',
      @port = 555,
      @enable_ssl = 1,
      @username = 'MyGmailSMTPEMAIL@gmail.com',
      @password = 'xxxxxxx' ;  
  GO
  
  EXECUTE msdb.dbo.sysmail_add_profileaccount_sp  
      @profile_name = 'P2PEmailNotifications',  
      @account_name = 'MyGmail',  
      @sequence_number =1 ;  
  GO
  </code></pre>
  
  <p><strong>Step # 4</strong></p>
  
  <p>Now, trying to execute dbmail by using below query:</p>
  
  <pre><code>EXEC [msdb].[dbo].[sp_send_dbmail] 
       @profile_name = 'P2PEmailNotifications', 
       @recipients = 'xxx.xxx.xxx@outlook.com', 
       @subject = @Subject2,
       @body = @Body2,
       @body_format = 'HTML'
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p>Now, there are no errors anywhere that I can find in my result window.</p>
  
  <p><a href="https://i.stack.imgur.com/i6uDs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i6uDs.png" alt="enter image description here"></a></p>
  
  <p><strong>Step # 5</strong></p>
  
  <p>So, I got these queries to check if there is any error while sending the dbmail  and run it:</p>
  
  <pre><code>SELECT * 
  FROM msdb..sysmail_event_log 
  ORDER BY log_id DESC
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4zAhW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4zAhW.png" alt="enter image description here"></a></p>
  
  <p>This is the error which is in the description column:</p>
  
  <blockquote>
    <p>The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 9 (2019-04-11T00:21:06). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 64.233.167.109:555).
    )</p>
  </blockquote>
  
  <pre><code>SELECT * FROM dbo.sysmail_sentitems
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ylr4b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ylr4b.png" alt="enter image description here"></a></p>
  
  <p>After seeing the error I have repeated the step 3 by changing the different gmail email and by changing the port 555 to 587 after that I have received below error in the description column  </p>
  
  <p><a href="https://i.stack.imgur.com/c11MK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c11MK.png" alt="enter image description here"></a></p>
  
  <p>Exception information</p>
  
  <blockquote>
    <p>Exception Type: Microsoft.SqlServer.Management.SqlIMail.Server.Common.BaseException</p>
    
    <p>Message: Could not retrieve item from the queue. Reason: the list of accounts which could send this mail is empty (probably due to the use of invalid profile).  </p>
    
    <p>Data: System.Collections.ListDictionaryInternal<br>
    TargetSite: Microsoft.SqlServer.Management.SqlIMail.Server.Controller.ICommand CreateSendMailCommand(Microsoft.SqlServer.Management.SqlIMail.Server.DataAccess.DBSession)<br>
    HelpLink: NULL<br>
    Source: DatabaseMailEngine</p>
  </blockquote>
  
  <p>StackTrace Information</p>
  
  <blockquote>
    <p>at Microsoft.SqlServer.Management.SqlIMail.Server.Controller.CommandFactory.CreateSendMailCommand(DBSession dbSession)<br>
    at Microsoft.SqlServer.Management.SqlIMail.Server.Controller.CommandRunner.Run(DBSession db)
       at Microsoft.SqlServer.Management.SqlIMail.IMailProcess.ThreadCallBack.MailOperation(Object obj)</p>
  </blockquote>
  
  <p><strong>Conclusion</strong></p>
  
  <p>I've got a queue of items with sent status "failed". As I describe my problem briefly. So, I need some answers from you developers that what I'm doing wrong in my above steps is I'm missing something or Is this a known issue with SQL Server 2014 that I haven't in my searches? Any other possible steps to get this mail sent?</p>