【发布时间】:2017-04-10 07:55:23
【问题描述】:
我正在尝试使用 SQL Server 2014 通过电子邮件发送 SQL 查询的结果。问题是电子邮件正在排队,但未传递给收件人。与服务器的连接存在一些问题。我得到的描述是:
由于邮件服务器故障,无法将邮件发送给收件人。 (使用帐户 1 发送邮件 (2017-04-05T16:05:09)。异常消息:无法连接到邮件服务器。(连接尝试失败,因为连接方在一段时间后没有正确响应,或建立连接失败,因为连接的主机未能响应 74.125.130.109:25)。
我的代码是:
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'MIS_Automation_Project',
@description = 'Mail account for office files.',
@email_address = 'my_email_address',
@display_name = 'MIS_Automation',
@mailserver_name = 'smtp.gmail.com' ;
-- Create a Database Mail profile
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'MIS_Automation',
@description = 'Profile used for mis automation project' ;
-- Add the account to the profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'MIS_Automation',
@account_name = 'MIS_Automation_Project',
@sequence_number =1 ;
-- Grant access to the profile to the DBMailUsers role
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'MIS_Automation',
@principal_name = 'guest',
@is_default = 1 ;
DECLARE @xml NVARCHAR(MAX)
DECLARE @body NVARCHAR(MAX)
SET @xml = CAST(( SELECT [clno] AS 'td','',[clname] AS 'td','',
[cladd] AS 'td'
FROM Client
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
SET @body ='<html><body><H3>Client Information</H3>
<table border = 1>
<tr>
<th> Client No </th> <th> Client Name </th> <th> Client Address </th>
</tr>'
SET @body = @body + @xml +'</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MIS_Automation', -- replace with your SQL Database Mail Profile
@body = @body,
@body_format ='HTML',
@recipients = 'recipient', -- replace with your email address
@subject = 'E-mail in Tabular Format' ;
我该如何解决这个问题?
【问题讨论】:
-
能否通过右击sql代理查看邮件错误日志
标签: sql-server email sql-server-2005 sql-server-2014-express