【发布时间】:2020-03-01 13:31:09
【问题描述】:
我正在设置基于触发器的邮件通知,在使用它时,我也遇到了错误。
配置文件设置如下:
EXECUTE msdb.dbo.sysmail_add_account_sp @account_name = 'TestMailAccount',
@description = 'Test Mail Account for sending notifications',
@email_address = 'my_gmail_id@gmail.com',
@display_name = 'Test Mail Notification',
@username = 'my_gmail_id@gmail.com',
@password = 'my_gmail_password',
@mailserver_name = 'smtp.gmail.com',
@port = 587,
@enable_ssl = 1;
EXECUTE msdb.dbo.sysmail_add_profile_sp @profile_name = 'TestMailProfile',
@description = 'Main test profile used to send notification email';
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp @profile_name = 'TestMailProfile',
@account_name = 'TestMailAccount',
@sequence_number = 2;
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'TestMailProfile',
@principal_name = 'public',
@is_default = 0;
现在要发送邮件,我执行了:
DECLARE @mail_body NVARCHAR(MAX);
SET @mail_body = CONCAT( N'<html>',
N'<body>',
N'<h1>Test Mail</h1>',
N'</body>',
N'</html>');
EXECUTE msdb.dbo.sp_send_dbmail
@profile_name = 'TestMailProfile',
@recipients = 'dest@gmail.com',
@subject = N'DB Test Mail',
@body = @mail_body,
@body_format = 'HTML';
在这之后,我检查了日志:
select * from sysmail_event_log
描述显示:
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 42 (2020-03-01T18:41:09). Exception Message: Cannot send mails to mail server. (The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at).
我已经启用了谷歌帐户的设置以使用不太安全的应用访问。
我不确定我错过了什么,任何帮助都将得到高度评价。
【问题讨论】:
-
你试过 465 端口吗?
-
@lptr: 没试过,使用端口 465,错误是“由于邮件服务器故障,无法将邮件发送给收件人。(使用帐户 43 发送邮件(2020- 03-01T19:25:06)。异常消息:无法向邮件服务器发送邮件。(发送邮件失败。)。”
-
用端口 587 测试它并且它工作正常
-
@lptr 你做了什么不同的事情吗?如果是这样,请分享脚本/设置等?
-
我已经使用了您的设置脚本(只是更改了帐户的凭据)。 (也开启了不太安全的应用访问)
标签: sql-server sql-server-2014 sql-server-2014-express sp-send-dbmail dbmail