配置数据库邮件太长了。
所以我想创建一个自动为我创建的脚本
DECLARE @YourEmail NVARCHAR(50) SET @YourEmail = '[email protected]' --Put here your E-mail
DECLARE @YourPassword NVARCHAR(50) SET @YourPassword = 'MyPassword' --Put here your E-mail
DECLARE @YourSMTPSserver NVARCHAR(50) SET @YourSMTPSserver = 'MySMTPserver' --Put here your SMTP Server
DECLARE @YourPort int SET @YourPort = '25' --Put here your SMTP port
-- Create a Database Mail account
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'SQL_Spring_Cleaning_Account',
@description = 'Mail account for SQL_Spring_Cleaning.',
@email_address = @YourEmail,
@replyto_address = @YourEmail,
@display_name = 'SQL_Spring_Cleaning Mailer',
@mailserver_name = @YourSMTPSserver,
@port = @YourPort,
@use_default_credentials = 0,
@username = @YourEmail,
@password = @YourPassword;
-- Create a Database Mail profile
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'SQL_Spring_Cleaning_Profile',
@description = 'Profile used for SQL_Spring_Cleaning mail.' ;
-- Add the account to the profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'SQL_Spring_Cleaning_Profile',
@account_name = 'SQL_Spring_Cleaning_Account',
@sequence_number =1 ;
-- Grant access to the profile to the DBMailUsers role
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'SQL_Spring_Cleaning_Profile',
@principal_name = 'ASPIRES3\franc',
@is_default = 0 ;
但不幸的是,SSMS 返回给我:
Msg 14607, Level 16, State 1, Procedure sysmail_verify_principal_sp, Line 49 [Batch Start Line 0]
principal name is not valid
错误明显在线
@principal_name = 'ASPIRES3\franc',
但我不明白这有什么问题
您使用的名称是 msdb 数据库中的用户吗?