title: Unable to clear SQL Server sysmail queue
body: <p>Last night due to some bad code, my SQL Server tried sending a million emails. After 10k the emails started going into queue. I immediately stopped the sysmail service using exec sysmail_stop_sp.</p>
  
  <p>Then I deleted all entries from <code>sysmail_allitems</code>, <code>sysmail_faileditems</code>, <code>sysmail_send_retries</code>, <code>sysmail_senditems</code> and <code>sysmail_unsentitems</code>.</p>
  
  <p>I also cleared <code>sysmail_event_log</code>.</p>
  
  <p>Assuming that it would clear my mail queue I started the sysmail services using </p>
  
  <pre><code>exec sysmail_start_sp
  </code></pre>
  
  <p>But to my surprise the sysmail is still trying to send emails but it cannot find them in <code>sysmail_allitems</code>.</p>
  
  <p>I checked the mail queue using <code>msdb.dbo.sysmail_help_queue_sp</code> and it shows queue with queue_type 'mail' showing those million emails queue.</p>
  
  <p>I rechecked all the tables and they all are empty. Where is this queue is being fetched?</p>
  
  <p>Though no email were sent but still the server tried each and every email which lasted for few hours.</p>
  
  <p>Any idea where the queue is fetched from?</p>