how to setup DatabaseMail(with MS Exchange Server)

本文介绍如何在SQL Server 2005中配置Database Mail服务,包括启用高级选项、设置邮件账户、创建邮件配置文件并授权所有用户使用等步骤。最后演示了发送邮件的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--SQL Server 2005 Surface Area Configuration
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Database Mail XPs', 1;
GO
RECONFIGURE
GO

-- Creates a new Database Mail account
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'FISADM',
@description = 'FISADM',
@email_address = 'FISADM@IACP.IAC',
@replyto_address = 'FISADM@IACP.IAC',
@display_name = 'FISADM@IACP.IAC',
@mailserver_name = 'iacp-mail3.iacp.iac',
@port = 25,
@username ='iacp/FISADM',
@password ='XXXX',
@enable_ssl = 0

-- Create a Database Mail profile
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'FISprofile',
@description = 'Profile used for FIS.'

-- Add the account to the profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'FISprofile',
@account_name = 'FISADM',
@sequence_number =1 ;

-- Grant access to the profile to all users in the msdb database
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'FISprofile',
@principal_name = 'public',
@is_default = 1 ;  -- later, you can update it through T-SQL: 'update sysmail_principalprofile set ...'

--After this configuration you can send mail by calling the system store procedure dbo.sp_send_dbmail
EXECUTE msdb.dbo.sp_send_dbmail
--@profile_name = 'FISprofile',
@recipients = 'cdq@gmail.com;',
@subject = 'MyDBMAIL',
@body = 'Test Email'

select sent_status,* from msdb.dbo.sysmail_allitems 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值