Aracılığıyla paylaş


Veritabanı posta kullanma

smo, veritabanı posta alt tarafından temsil edilen SqlMailtarafından başvurulan nesne Mailözellik. smo kullanarak SqlMailnesne, veritabanı posta alt sistemini yapılandırmak ve profillerini yönetmek ve posta hesapları. smo SqlMailnesnesinin ait olduğu Servernesne, posta hesapları kapsamını sunucu düzeyinde olduğunu anlamı.

Örnekler

Sunulan kod örneklerinden herhangi birini kullanmak için, programlama ortamını, programlama şablonunu ve uygulamanızı oluşturacağınız programlama dilini seçmeniz gerekecektir. Daha fazla bilgi için, bkz. Visual Studio'da Visual Basic smo proje oluşturun.NET veya Visual Studio'da Visual C# smo proje oluşturun.NET.

Programları kullanan SQL ServerDatabase Mail, size gerekir dahil İthalat posta ad hak kazanmak için deyimi. INSERT deyimi birbiri ardına Importsdeyimleri, uygulamadaki tüm bildirimlerden önce gibi:

Imports Microsoft.SqlServer.Management.Smo

Imports Microsoft.SqlServer.Management.Common

Imports Microsoft.SqlServer.Management.Smo.Mail

Visual Basic kullanarak bir veritabanı posta hesabı oluşturma

Bu kod örneği nasıl smo bir e-posta hesabı oluşturmak için gösterir. Veritabanı posta tarafından temsil edilen SqlMailnesne ve başvurduğu Mailözelliği Servernesnesini. smo program aracılığıyla veritabanı posta yapılandırmak için kullanılabilir, ama göndermek ya da ele alınan e-posta için kullanılamaz.

VB.NET

'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# kullanarak bir veritabanı posta hesabı oluşturma

Bu kod örneği nasıl smo bir e-posta hesabı oluşturmak için gösterir. Veritabanı posta tarafından temsil edilen SqlMailnesne ve başvurduğu Mailözelliği Servernesnesini. smo program aracılığıyla veritabanı posta yapılandırmak için kullanılabilir, ama göndermek ya da ele alınan e-posta için kullanılamaz.

{
         //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, "AdventureWorks2012 Administrator", "AdventureWorks2012 Automated Mailer", "Mail account for administrative e-mail.", "dba@Adventure-Works.com"); 
           a.Create();  
}
{
         //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, "AdventureWorks2012 Administrator", "AdventureWorks2012 Automated Mailer", "Mail account for administrative e-mail.", "dba@Adventure-Works.com"); 
           a.Create();  
}

PowerShell kullanarak bir veritabanı posta hesabı oluşturma

Bu kod örneği nasıl smo bir e-posta hesabı oluşturmak için gösterir. Veritabanı posta tarafından temsil edilen SqlMailnesne ve başvurduğu Mailözelliği Servernesnesini. smo program aracılığıyla veritabanı posta yapılandırmak için kullanılabilir, ama göndermek ya da ele alınan e-posta için kullanılamaz.

PowerShell

#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()

#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()