Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Scripting setup dari database mail

AFAIK, tidak ada cara untuk membuat skrip ini dari SSMS tetapi Anda dapat membuat skrip yang dapat diangkut dalam TSQL sekali dan menggunakannya kembali di semua server. Berikut adalah contoh yang baik untuk membantu Anda memulainya:

USE [master]
GO
sp_configure 'show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'Database Mail XPs',1
GO
RECONFIGURE 
GO
-- Create a New Mail Profile for Notifications
EXECUTE msdb.dbo.sysmail_add_profile_sp
       @profile_name = 'DBA_Notifications',
       @description = 'Profile for sending Automated DBA Notifications'
GO
-- Set the New Profile as the Default
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'DBA_Notifications',
    @principal_name = 'public',
    @is_default = 1 ;
GO
-- Create an Account for the Notifications
EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'SQLMonitor',
    @description = 'Account for Automated DBA Notifications',
    @email_address = '[email protected]',  -- Change This
    @display_name = 'SQL Monitor',
    @mailserver_name = 'smtp.domain.com'  -- Change This
GO
-- Add the Account to the Profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'DBA_Notifications',
    @account_name = 'SQLMonitor',
    @sequence_number = 1
GO

Pilihan lainnya adalah memanfaatkan SMO, baik melalui .NET atau PowerShell untuk menghasilkan skrip. Referensi SMO untuk ini adalah:

Kelas SQLMail

PEMBARUAN:

Inilah betapa mudahnya membuat skrip ini dengan Powershell dan SMO:

[void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo");

#Set the server to script from
$ServerName = "ServerName";

#Get a server object which corresponds to the default instance
$srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server $ServerName

#Script Database Mail configuration from the server
$srv.Mail.Script();



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara mengubah String ke Hex dan sebaliknya?

  2. SQL Server 2012 meminta data Access 2007 menggunakan kesalahan OPENROWSET

  3. Apa yang harus dilakukan dari tipe tunggu ASYNC NETWORK IO?

  4. sql server Sisipkan csv secara massal dengan data yang memiliki koma

  5. Server Sql upser cepat 2008 R2