简体   繁体   English

sql server sp_send_dbmail

[英]sql server sp_send_dbmail

I am using SQL Server's sp_send_dbmail stored procedure to send mail via the database. 我使用SQL Server的sp_send_dbmail存储过程通过数据库发送邮件。

But when I execute that procedure it's shutting down the db mail procedure. 但是当我执行该程序时,它正在关闭db邮件程序。 I tried to start it again by sysmail_start_sp . 我尝试通过sysmail_start_sp再次启动它。 But it's again shutting down in 7-8 seconds. 但它又在7-8秒内再次关闭。

I tried with the code below: 我试过下面的代码:

EXEC msdb..sp_send_dbmail @profile_name = 'Test',
@recipients = 'abc@gmail.com',
@subject = 'test mail',
@body_format = 'HTML',
@body = 'test mail',
@from_address = 'xyz@yahoo.com'

When I tried to check the error log I found the below error: 当我尝试检查错误日志时,我发现以下错误:

Message: 信息:

The read on the database failed. 对数据库的读取失败。 Reason: The error description is 'Whitespace is not allowed at this location.'.Data: System.Collections.ListDictionaryInternalTargetSite: Microsoft.SqlServer.Management.SqlIMail.Server.Objects.QueueItem GetQueueItemFromCommand(System.Data.SqlClient.SqlCommand)HelpLink: NULLSource: DatabaseMailEngineStackTrace Information=================== 原因:错误描述为'此位置不允许空格。'。数据:System.Collections.ListDictionaryInternalTargetSite:Microsoft.SqlServer.Management.SqlIMail.Server.Objects.QueueItem GetQueueItemFromCommand(System.Data.SqlClient.SqlCommand)HelpLink: NULLSource:DatabaseMailEngineStackTrace信息===================

Also when I checked sql email log history I found this error: 此外,当我检查sql电子邮件日志历史记录时,我发现此错误:

Mail not queued. 邮件没有排队。 Database Mail is stopped. 数据库邮件已停止。 Use sysmail_start_sp to start Database Mail. 使用sysmail_start_sp启动数据库邮件。

Whenever you try to send Test mail from Database mail; 每当您尝试从数据库邮件发送测试邮件时; it throws below error message: 它会抛出以下错误消息:

Msg 14641, Level 16, State 1, Procedure sp_send_dbmail, Mail not queued. 消息14641,级别16,状态1,过程sp_send_dbmail,邮件未排队。 Database Mail is stopped. 数据库邮件已停止。 Use sysmail_start_sp to start Database Mail. 使用sysmail_start_sp启动数据库邮件。


  1. First of all make sure that Service Broker Message Delivery in Databases is enabled by executing the following command in SSMS: 首先,确保通过在SSMS中执行以下命令来启用数据库中的Service Broker消息传递:

     SELECT is_broker_enabled FROM sys.databases WHERE name = 'msdb' 

    If the result of above query is 0, then activate the service broker. 如果上述查询的结果为0,则激活服务代理。

    Activating Service Broker allows messages to be delivered to the database. 激活Service Broker允许将消息传递到数据库。 A Service Broker endpoint must be created to send and receive messages from outside of the instance. 必须创建Service Broker端点才能从实例外部发送和接收消息。

    To activate Service Broker in a database use the following command: 要在数据库中激活Service Broker,请使用以下命令:

     USE master ; GO ALTER DATABASE DatabaseName SET ENABLE_BROKER ; GO 
  2. If the Service Broker is enabled then confirm whether Database Mail is enabled or not by executing below queries in SQL Server Management Studio: 如果启用了Service Broker,则通过在SQL Server Management Studio中执行以下查询来确认是否启用了数据库邮件:

     sp_configure 'show advanced', 1 GO RECONFIGURE GO sp_configure GO 

    If the result set shows run_value as 1 then Database Mail is enabled. 如果结果集将run_value显示为1,则启用数据库邮件。

  3. If the Database Mail option is disabled then run the below queries to enable it: 如果禁用了“数据库邮件”选项,请运行以下查询以启用它:

     sp_configure 'Database Mail XPs', 1; GO RECONFIGURE; GO sp_configure 'show advanced', 0; GO RECONFIGURE; GO 
  4. Once the Database Mail is enabled then to start Database Mail External Program use the below mentioned query on msdb database: 启用数据库邮件后,启动数据库邮件外部程序在msdb数据库上使用下面提到的查询:

     USE msdb ; EXEC msdb.dbo.sysmail_start_sp; 
  5. To confirm that Database Mail External Program is started, run the query mentioned below : 要确认已启动数据库邮件外部程序,请运行下面提到的查询:

     EXEC msdb.dbo.sysmail_help_status_sp; 
  6. If the Database Mail external program is started then check the status of mail queue using below statement: 如果启动了数据库邮件外部程序,则使用以下语句检查邮件队列的状态:

     EXEC msdb.dbo.sysmail_help_queue_sp @queue_type = 'mail'; 

There are few things to troubleshoot, firstly check to make sure database Mail is enabled by executing the following 要解决的问题很少,首先检查以确保通过执行以下操作来启用数据库Mail

SELECT is_broker_enabled FROM sys.databases WHERE name = 'msdb'

If the result of above is 0 , activate the service broker by following this guide 如果上述结果为0 ,请按照本指南激活服务代理

If the result of above is 1 , then check the status of Database Mail, execute the following statement: 如果上面的结果为1 ,则检查数据库邮件的状态,执行以下语句:

EXECUTE dbo.sysmail_help_status_sp

To start Database Mail in a mail host database, run the following command in the msdb database: 要在邮件主机数据库中启动Database Mail,请在msdb数据库中运行以下命令:

EXECUTE dbo.sysmail_start_sp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM