Kon*_* Z. 0 database-mail sql-server-2008
我为sysadmin准备了脚本,用于创建和配置数据库邮件配置文件,帐户和操作员.他运行脚本,所以我创建了临时工作,但失败了.然后我在作业失败时设置电子邮件通知.我运行Job,但没有发送电子邮件.然后我尝试运行msdb.dbo.sp_send_dbmail 程序,使用相同的操作员,我收到了电子邮件.当作业失败时,不发送电子邮件的原因是什么?如果在作业失败时使用电子邮件通知正在运行哪个程序 - 它是否与sp_send_dbmail?不同?
另一件事是在数据库邮件日志中没有关于发送电子邮件状态的信息(它是空的) - 也许我没有权限看到日志?
我将配置文件设置为公共,正在运行dbo.sysmail_add_principalprofile_sp procedure,但是当我尝试发送运行msdb.dbo.sp_send_dbmail已记录为dbowner 的电子邮件时,我收到错误:EXECUTE权限被拒绝..为什么只有当我以用户身份登录时它才有效?
我正在使用SQL Server 2008.
这是一个T-SQL代码,我传递给sysadmin来创建和配置数据库邮件.
-- Create a Database Mail account
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'Mail Account',
@description = 'Mail account for administrative e-mail.',
@email_address = 'xx@xx.pl',
@display_name = 'Job failure notification',
@mailserver_name = 'xx.xx.xxx' ,
@username = 'aaa',
@password = 'xxx'
-- Create a Database Mail profile
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'Database Mail Profile',
@description = 'Profile used for job failure notifications.' ;
-- Add the account to the profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'Database Mail Profile',
@account_name = 'Mail Account',
@sequence_number =1 ;
-- Enable Mail profile in SQL Agent
EXEC master.dbo.xp_instance_regwrite
N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'DatabaseMailProfile',
N'REG_SZ',
N'Database Mail Profile'
GO
-- Create new operator
EXEC msdb.dbo.sp_add_operator @name=N'SQL Job Failure',
@enabled=1,
@weekday_pager_start_time=90000,
@weekday_pager_end_time=180000,
@saturday_pager_start_time=90000,
@saturday_pager_end_time=180000,
@sunday_pager_start_time=90000,
@sunday_pager_end_time=180000,
@pager_days=0,
@email_address=N'xx@xx.pl',
@category_name=N'[Uncategorized]'
GO
-- Setting profile as public
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'Database Mail Profile',
@principal_name = 'public',
@is_default = 0 ;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15148 次 |
| 最近记录: |