sql-server - sp_send_dbmail 未在执行 sql 任务中执行而不会引发任何错误

标签 sql-server ssis sp-send-dbmail

我是 SSIS 的新手。我在一个存储过程中执行 sp_send_dbmail 时遇到问题,该存储过程由 SSIS 中的执行 SQL 任务运行。主要问题是,即使我运行此 SP 的配置文件不存在,它也不会抛出任何错误并成功完成。我怀疑存在配置问题,但无法诊断。

我发现我的临时服务器上未配置 SMTP。这可能是唯一的原因吗?即使是这样,它至少应该抛出一个错误,但在日志中我没有看到任何相同的错误消息。

此外,如果我直接通过 SQL 运行此 SP,则会收到“配置文件不存在”错误。但是当我通过SSIS运行相同的SP(执行sql任务)时,它执行成功。

有关此问题的任何指导都会有很大帮助。

这就是我调用 sp_send_dbmail 的方式。

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Stagging Trigger',
@recipients = 'myemailID@test.com',
@subject = 'this is the SP to send mail from SP'

最佳答案

sp_send_dbmail 仅对邮件进行排队。不尝试发送、不验证电子邮件配置文件、无法提出您所提示的任何缺失的错误。

在此处阅读如何检查排队电子邮件的状态:Check the Status of E-Mail Messages Sent With Database Mail :

USE msdb ;  
GO  

-- Show the subject, the time that the mail item row was last  
-- modified, and the log information.  
-- Join sysmail_faileditems to sysmail_event_log   
-- on the mailitem_id column.  
-- In the WHERE clause list items where danw was in the recipients,  
-- copy_recipients, or blind_copy_recipients.  
-- These are the items that would have been sent  
-- to danw.  

SELECT items.subject,  
    items.last_mod_date  
    ,l.description FROM dbo.sysmail_faileditems as items  
INNER JOIN dbo.sysmail_event_log AS l  
    ON items.mailitem_id = l.mailitem_id  
WHERE items.recipients LIKE '%danw%'    
    OR items.copy_recipients LIKE '%danw%'   
    OR items.blind_copy_recipients LIKE '%danw%'  
GO  

有关该主题的更多文章:

关于sql-server - sp_send_dbmail 未在执行 sql 任务中执行而不会引发任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55318969/

相关文章:

sql - SSIS动态查询

sql-server - SQL Server sp_send_dbmail - 如何将邮件发送到 Gmail?

sql-server - msdb.dbo.sysmail_mailitems 上的 sent_status 值的含义

c# - 参数 C# SQL 出错

sql - 如果表有一行或多行存在一个条件,则获取 ID

sql - 为什么 "select count(*)"从无返回 1

ssis - Visual Studio 2019 新项目不包括已安装的 SSIS

sql-server - 错误处理 - 确定 sp_executesql 是否是源

sql - 在 SSIS 中将月份名称更改为月份编号

html - 将 SQL 查询结果表转换为用于电子邮件的 HTML 表