exec sp_configure 'show advanced options',1 RECONFIGURE WITH OVERRIDE go exec sp_configure 'database mail xps',1 RECONFIGURE WITH OVERRIDE go
--2.创建邮件帐户信息 EXEC msdb..sysmail_add_account_sp @ACCOUNT_NAME ='ETLErrorMailLog', -- 邮件帐户名称 @EMAIL_ADDRESS ='******@126.com' , -- 发件人邮件地址 @DISPLAY_NAME ='系统管理员', -- 发件人姓名 @REPLYTO_ADDRESS =NULL, @DESCRIPTION = NULL, @MAILSERVER_NAME = 'SMTP.126.COM', -- 邮件服务器地址 @MAILSERVER_TYPE = 'SMTP', -- 邮件协议 @PORT =25, -- 邮件服务器端口 @USERNAME = '******@126.com', -- 用户名 @PASSWORD = '******', -- 密码 @USE_DEFAULT_CREDENTIALS =0, @ENABLE_SSL =0, @ACCOUNT_ID = NULL GO
--3.数据库配置文件 if exists(select name from msdb..sysmail_profile where name=N'ETLErrorProfileLog') begin exec msdb..sysmail_delete_profile_sp @profile_name='ETLErrorProfileLog' end exec msdb..sysmail_add_profile_sp @profile_name = 'ETLErrorProfileLog', -- profile 名称 @description = '数据库邮件配置文件', -- profile 描述 @profile_id = null go
--4.用户和邮件配置文件相关联 exec msdb..sysmail_add_profileaccount_sp @profile_name = 'ETLErrorProfileLog', -- profile 名称 @account_name = 'ETLErrorMailLog', -- account 名称 @sequence_number = 1 -- account 在 profile 中顺序
--5.发送文本测试邮件 exec msdb..sp_send_dbmail @profile_name='ETLErrorProfileLog', @recipients='******@qq.com', --收件人 @subject='Test title this is test ', @body=N'z中文邮件内容 中文邮件内容' go
我在本机设置成功后,又在服务器上设置了一遍,但服务器上无论如何都不能发送邮件,邮件发送状态描述里显示(我使用的SMTP服务器是smtp.gmail.com):
由于邮件服务器故障,无法将邮件发送给收件人。 (使用帐户 1 (2010-05-24T09:57:05) 发送邮件。 异常邮件: 无法将邮件发送到邮件服务器。 (操作已超时。)。 )
或
由于邮件服务器故障,无法将邮件发送给收件人。 (使用帐户 1 (2010-05-24T16:14:16) 发送邮件。 异常邮件: 无法连接到邮件服务器。 (由于目标机器积极拒绝,无法连接。 74.125.127.109:587)。 )
最后检查才发现,原来是服务器上的McAfee阻止了SMTP端口外连:
2010-5-24 16:15:16 被端口阻挡规则阻挡 C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Binn\DatabaseMail.exe 防病毒标准保护:禁止群发邮件蠕虫发送邮件 74.125.127.109:587
由此,设置好McAfee后即可正常发送邮件了。
转载于:https://www.cnblogs.com/daretodream/archive/2012/02/08/2342547.html
来源:https://www./content-2-258801.html
|