我試圖通過使用SQL Server 2014的電子郵件發送SQL查詢的結果。問題是電子郵件正在排隊,但未傳遞給收件人。與服務器的連接存在一些問題。我得到的描述是:郵件排隊但未在SQL Server 2014中傳遞
由於郵件服務器故障,郵件無法發送給收件人。 (使用帳戶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代理檢查電子郵件錯誤日誌 – TheGameiswar