SQLserver发送邮件

 

--server 配置
sp_configure 'show advanced options',1
go
RECONfigURE
go
sp_configure 'sql Mail XPs',1
go
RECONfigURE
go

sp_configure 'Database Mail XPs',1
go
RECONfigURE
go

--1 基本配置ファイルを作成
EXECUTE msdb.dbo.sysmail_help_profile_sp
--2 アカウントを作成
EXECUTE msdb.dbo.sysmail_help_account_sp ;
--3 基本配置ファイルとアカウント結合し順番を指定
EXECUTE msdb.dbo.sysmail_help_profileaccount_sp
--4 既定のアカウントを指定
EXECUTE msdb.dbo.sysmail_help_principalprofile_sp ;
--5 システムパラメータを指定
EXECUTE msdb.dbo.sysmail_help_configure_sp ;

 

exec dbo.sp_send_dbmail
@profile_name='myMail',
@recipients='XXX@163.com',
@subject='メールテスト',
@body='hello'

exec dbo.sp_send_dbmail
select * from sysmail_log
select * from sysmail_sentitems

 

use master
go
exec sp_configure 'show advanced options',1
go
reconfigure
go
exec sp_configure 'Database mail XPs',1
go
reconfigure
go

--1 基本配置ファイルを作成
EXECUTE msdb.dbo.sysmail_help_profile_sp '1','fan'
--2 アカウントを作成
EXECUTE msdb.dbo.sysmail_help_account_sp ;
--3 基本配置ファイルとアカウント結合し順番を指定
EXECUTE msdb.dbo.sysmail_help_profileaccount_sp
--4 既定のアカウントを指定
EXECUTE msdb.dbo.sysmail_help_principalprofile_sp ;
--5 システムパラメータを指定
EXECUTE msdb.dbo.sysmail_help_configure_sp

exec msdb.dbo.sysmail_add_profile_sp 'fan',''

EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'fan_mail',
    @email_address = 'xxx@dl.cn',
    @display_name = 'fan',
    @mailserver_name = 'mail.dl.cn',
    @username= 'xxx@dl.cn',
    @password ='fh13084178517',
    @use_default_credentials ='0';

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp 1,null,1,1

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp 1,1

EXEC msdb.dbo.sp_send_dbmail
 @profile_name = 'fan',
@recipients = 'xxx@dl.cn',
@subject = 'myTest',
@query = 'select * from test.dbo.a',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'a.txt',
@body='my love,hhhhh'

exec msdb.dbo.sp_send_dbmail
select * from msdb.dbo.sysmail_log
select * from msdb.dbo.sysmail_sentitems

select * from sysmail_log
select * from sysmail_sentitems

EXEC msdb.dbo.sp_send_dbmail
 @profile_name = 'fan',
@copy_recipients='xxx@163.com',
@blind_copy_recipients ='xxx@vip.163.com',@subject = 'myTest',@file_attachments = 'c:\5.txt.txt;c:\a\5.txt.txt',@body='my love,hhhhh',@importance = 'High'

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...