如何在 SQL 服务器的 Express Edition 上设置邮件配置文件?

How to set up mailing profile on a Express Edition of SQL Server?

是否可以在没有 "Database Mail" 的情况下在 SQL Server Management Studio 上创建邮件配置文件?

我假设您可以使用 MSDB 中的存储过程对其进行设置。我没试过这个,但你可能想试一试。

看看...

sysmail_add_account_sp

...和相关的存储过程。

sysmail_add_account_sp MSDN documentation

默认情况下,SQL Express 不支持通过 GUI 向导配置数据库邮件,但是可以通过脚本进行配置。

这些detailed instructions指导你。

Here 是一个详细介绍过程的博客。

以下是博客内容的粗略副本,以确保此答案不会过时。

  1. 启用数据库邮件存储过程:

    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Database Mail XPs', 1;
    GO
    RECONFIGURE
    GO
    
  2. 使用 sysmail_add_account_sp 创建 sysmail 帐户:

    EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'MailTest',
    @description = 'Sent Mail using MSDB',
    @email_address = 'umashankar@queryingsql.com',
    @display_name = 'umashankar',
    @username='umashankar@queryingsql.com',
    @password='password',
    @mailserver_name = 'mail.queryingsql.com'
    
  3. 创建数据库配置文件 sysmail_add_profile_sp:

    EXECUTE msdb.dbo.sysmail_add_profile_sp
    @profile_name = 'MailTest',
    @description = 'Profile used to send mail'
    
  4. 将帐户映射到配置文件 sysmail_add_profileaccount_sp:

    EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'MailTest',
    @account_name = 'MailTest',
    @sequence_number = 1
    
  5. 授予数据库主体(数据库用户或角色)使用数据库配置文件:

    EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'MailTest',
    @principal_name = 'public',
    @is_default = 1 ;
    
    --A principal_name of 'public' makes this profile a public profile, granting access to all principals in the database.
    
  6. 测试 sp_send_dbmail:

    exec msdb.dbo.sp_send_dbmail 
    @profile_name = 'MailTest', 
    @recipients = 'receiver@queryingsql.com', 
    @subject = 'Mail Test', 
    @body = 'Mail Sent Successfully', 
    @body_format = 'text'
    

您还应该查找每个存储过程的 MSDN 文档,以确保您正确配置了系统。