我们有一个SQL作业,每天运行,将emais发送给我们的驱动程序,并提供第二天的日程安排。
对于85%的驱动程序来说,电子邮件无法从SQL服务器中取出。其他15%的发送没有错误。
我检查了日志并看到了以下错误:
由于邮件服务器故障,无法将邮件发送给收件人。(使用帐户3发送邮件(2020-03-22T16:00:06)异常消息:无法向邮件服务器发送邮件。(发送邮件失败)。)
有没有人知道出了什么问题,或者如何得到更详细的错误?
这个问题是在我们将服务器迁移到一个新的数据中心之后开始的。
我们正在Windows 2008 R2主机上运行Server 2014。
发布于 2020-05-12 18:25:18
从这个问题中:
首先,我将看到以下查询的结果(因为您已经启动并运行了dbmail ):
--==============================================================
-- I’m doing a TOP 100 on these next several queries as they tend
-- to contain a great deal of data. Obviously if you need to get
-- more than 100 rows this can be changed.
-- Check the database mail event log.
-- Particularly for the event_type of "error". These are where you
-- will find the actual sending error.
--==============================================================
SELECT TOP 100 *
FROM msdb.dbo.sysmail_event_log
ORDER BY last_mod_date DESC;
--==============================================================
-- Check the actual emails queued
-- Look at sent_status to see 'failed' or 'unsent' emails.
--==============================================================
SELECT TOP 100 *
FROM msdb.dbo.sysmail_allitems
ORDER BY last_mod_date DESC;
--==============================================================
-- Check the emails that actually got sent.
-- This is a view on sysmail_allitems WHERE sent_status = 'sent'
--==============================================================
SELECT TOP 100 *
FROM msdb.dbo.sysmail_sentitems
ORDER BY last_mod_date DESC;
--==============================================================
-- Check the emails that failed to be sent.
-- This is a view on sysmail_allitems WHERE sent_status = 'failed'
--==============================================================
SELECT TOP 100 *
FROM msdb.dbo.sysmail_faileditems
ORDER BY last_mod_date DESC根据这些查询的结果,有几种方法可以排除故障。
也许问题不在sql中?为此,我使用powershell发送了几封测试邮件,看看是否一切正常。(更改下面脚本中的详细信息)
$smtpServer = "200.1.1.223"
$smtpPort = 25
$emailFrom = "donotreply@xxxxx.co.uk"
$emailTo = "mmiorelli@xxxxx.co.uk"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Port = $smtpPort
$subject = "ccatsql"
$body = "test email from ccatsql "
$smtp.Send($emailFrom, $emailTo, $subject, $body)检查是否安装了.Net框架3.5 --这可能导致奇怪的错误,即使在sql server 2016中也是如此。
根据我自己的经验,有时,如果.NET 3.5或任何底层组件丢失或损坏,则不会将错误写入任何日志。
要解决这个问题(只有如果这是问题的话),您可以实现以下任何一个:
您可以使用notepad.exe或任何其他编辑器来编辑它。
只需确保您使用UTF-8编码保存它(在notepad.exe中,选择save .在编码组合框中,选择UTF-8):
请参阅有关这个答案的更多信息。
https://dba.stackexchange.com/questions/267020
复制相似问题