配置資料庫郵件

2021-08-26 23:57:10 字數 1499 閱讀 9864

--配置資料庫郵件指令碼

--1.開啟資料庫郵件

exec sp_configure 'show advanced options',1

goreconfigure

goexec sp_configure 'database mail xps',1

goreconfigure

go--2.建立郵件帳戶資訊

exec msdb.dbo.sysmail_add_account_sp

@account_name ='rx',--郵件帳戶名稱

@email_address ='[email protected]',--發件人郵件位址

@display_name ='jw',--發件人姓名

@replyto_address ='[email protected]',

@description = '郵件報警',

@mailserver_name = '***',--郵件伺服器位址

@mailserver_type = 'smtp',--郵件協議

@port =25,--郵件伺服器端口

@username = 'xx',--使用者名稱

@password = '*********',--密碼

@use_default_credentials =0,--指定是否使用 sql server 資料庫引擎的憑據將郵件傳送到 smtp 伺服器。

@enable_ssl =0,

@account_id = null

go--3.1資料庫郵件配置檔案

if exists(select name from msdb.dbo.sysmail_profile where name=n'jw')

begin

exec msdb.dbo.sysmail_delete_profile_sp

@profile_name='jw'

end-- 3.2資料庫郵件帳號新增到郵件配置檔案中

exec msdb.dbo.sysmail_add_profile_sp

@profile_name = 'jw',--profile名稱

@description = '資料庫郵件配置檔案',--profile描述

@profile_id = null

go--4.使用者和郵件配置檔案相關聯

exec msdb.dbo.sysmail_add_profileaccount_sp

@profile_name = 'jw',--profile名稱

@account_name = 'rx',--account名稱

@sequence_number = 1--account 在profile 中順序

go--5.將配置檔案設定為預設的公共配置檔案

exec msdb.dbo.sysmail_add_principalprofile_sp

@principal_name = 'public',

@profile_name = 'jw',

@is_default = 1;

go

配置資料庫郵件

配置資料庫郵件,傳送郵件先要啟用資料庫郵件.可以從外圍應用配置器中啟用 見圖一 在sql server management studio中右擊資料庫郵件 配置資料庫郵件 見圖二 在 圖三 選擇通過執行以下任務來安裝資料庫郵件,在 圖四 指定乙個smtp賬號其中包括,賬號名 administrato...

資料庫郵件

直接發文字 exec msdb.dbo.sp send dbmail profile name zulin recipients 8711 gs4.comp body test subject 資料庫郵件測試 帶查詢結果 exec msdb.dbo.sp send dbmail profile na...

paip 資料庫發郵件通知配置

paip.資料庫發郵件通知配置 作者attilax email 1466519819 qq.com 建立了維護計畫 通知操作員,run,失敗.檢視sql,execute msdb.dbo.sp notify operator name n attilax subject n bek ok2 body...