데이터베이스 메일 사용
적용 대상:SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse Analytics
SMO에서 데이터베이스 메일 하위 시스템은 속성에서 SqlMail 참조하는 개체로 Mail 표시됩니다. SMO SqlMail 개체를 사용하여 데이터베이스 메일 하위 시스템을 구성하고 프로필 및 메일 계정을 관리할 수 있습니다. SMO SqlMail 개체는 서버 개체에 속합니다. 즉, 메일 계정의 범위가 서버 수준에 있습니다.
예
제공된 코드 예제를 사용하려면 프로그래밍 환경, 프로그래밍 템플릿 및 애플리케이션을 만들 프로그래밍 언어를 선택해야 합니다. 자세한 내용은 Visual Studio .NET에서 Visual C# SMO 프로젝트 만들기를 참조하세요.
SQL Server 데이터베이스 메일을 사용하는 프로그램의 경우 메일 네임스페이스를 한정하려면 Imports 문을 포함해야 합니다. 다음과 같이 애플리케이션의 선언 앞에 다른 Imports 문 뒤에 문을 삽입합니다.
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Imports Microsoft.SqlServer.Management.Smo.Mail
Visual Basic을 사용하여 데이터베이스 메일 계정 만들기
이 코드 예제에서는 SMO에서 전자 메일 계정을 만드는 방법을 보여줍니다. 데이터베이스 메일은 개체로 SqlMail 표시되고 개체의 Server 속성에서 Mail 참조됩니다. SMO는 프로그래밍 방식으로 데이터베이스 메일을 구성하는 데 사용할 수 있지만 받은 전자 메일을 보내거나 처리하는 데는 사용할 수 없습니다.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server()
'Define the Database Mail service with a SqlMail object variable and reference it using the Server Mail property.
Dim sm As SqlMail
sm = srv.Mail
'Define and create a mail account by supplying the Database Mail service, name, description, display name, and email address arguments in the constructor.
Dim a As MailAccount
a = New MailAccount(sm, "AdventureWorks Administrator", "AdventureWorks Automated Mailer", "Mail account for administrative e-mail.", "dba@Adventure-Works.com")
a.Create()
Visual C#을 사용하여 데이터베이스 메일 계정 만들기
이 코드 예제에서는 SMO에서 전자 메일 계정을 만드는 방법을 보여줍니다. 데이터베이스 메일은 개체로 SqlMail 표시되고 개체의 Server 속성에서 Mail 참조됩니다. SMO는 프로그래밍 방식으로 데이터베이스 메일을 구성하는 데 사용할 수 있지만 받은 전자 메일을 보내거나 처리하는 데는 사용할 수 없습니다.
{
//Connect to the local, default instance of SQL Server.
Server srv = default(Server);
srv = new Server();
//Define the Database Mail service with a SqlMail object variable
//and reference it using the Server Mail property.
SqlMail sm;
sm = srv.Mail;
//Define and create a mail account by supplying the Database Mail
//service, name, description, display name, and email address
//arguments in the constructor.
MailAccount a = default(MailAccount);
a = new MailAccount(sm, "AdventureWorks2022 Administrator", "AdventureWorks2022 Automated Mailer", "Mail account for administrative e-mail.", "dba@Adventure-Works.com");
a.Create();
}
PowerShell을 사용하여 데이터베이스 메일 계정 만들기
이 코드 예제에서는 SMO에서 전자 메일 계정을 만드는 방법을 보여줍니다. 데이터베이스 메일은 개체로 SqlMail 표시되고 개체의 Server 속성에서 Mail 참조됩니다. SMO는 프로그래밍 방식으로 데이터베이스 메일을 구성하는 데 사용할 수 있지만 받은 전자 메일을 보내거나 처리하는 데는 사용할 수 없습니다.
#Connect to the local, default instance of SQL Server.
#Get a server object which corresponds to the default instance
$srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server
#Define the Database Mail; reference it using the Server Mail property.
$sm = $srv.Mail
#Define and create a mail account by supplying the Database Mail service,
#name, description, display name, and email address arguments in the constructor.
$a = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Mail.MailAccount -argumentlist $sm, `
"Adventure Works Administrator", "Adventure Works Automated Mailer",`
"Mail account for administrative e-mail.", "dba@Adventure-Works.com"
$a.Create()
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기