建立 Database Mail 帳戶Create a Database Mail Account

本主題的適用對象: 是SQL Server沒有Azure SQL Database沒有Azure SQL 資料倉儲沒有Parallel Data WarehouseTHIS TOPIC APPLIES TO: yesSQL ServernoAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

您可以使用 「Database Mail 組態精靈」Transact-SQLTransact-SQL ,建立 Database Mail 帳戶。Use either the Database Mail Configuration Wizard or Transact-SQLTransact-SQL to create a Database Mail account.

開始之前Before You Begin

必要條件Prerequisites

  • 判斷您用於傳送電子郵件之 Simple Mail Transfer Protocol (SMTP) 伺服器的伺服器名稱和通訊埠編號。如果 SMTP 伺服器需要驗證,請判斷 SMTP 伺服器的使用者名稱和密碼。Determine the server name and port number for the Simple Mail Transfer Protocol (SMTP) server you use to send e-mail.If the SMTP server requires authentication, determine the user name and password for the SMTP server.

  • (選擇性) 您也可以指定伺服器的類型和伺服器的通訊埠編號。Optionally, you may also specify the type of the server and the port number for the server. 外寄郵件的伺服器類型一律為 'SMTP'。The server type is always 'SMTP' for outgoing mail. 大部分 SMTP 伺服器會使用通訊埠 25 (預設值)。Most SMTP servers use port 25, the default.

使用 Database Mail 組態精靈Using Database Mail Configuration Wizard

使用精靈建立 Database Mail 帳戶To create a Database Mail account using a Wizard

  • 在 [物件總管] 中,連接到想要在其上設定 Database Mail 的 SQL ServerSQL Server 執行個體,並展開伺服器樹狀目錄。In Object Explorer, connect to the SQL ServerSQL Server instance you want to configure Database Mail on, and expand the server tree.

  • 展開 [管理] 節點。Expand the Management node

  • 按兩下 Database Mail,開啟 [Database Mail 組態精靈]。Double Click Database Mail to open the Database Mail Configuration Wizard.

  • [選取組態工作] 頁面上,選取 [管理 Database Mail 帳戶和設定檔],並按 [下一步]On the Select Configuration Task page, select Manage Database Mail accounts and profiles, and click Next.

  • [管理設定檔和帳戶] 頁面上,選取 [建立新帳戶] ,並按 [下一步]On the Manage Profiles and Accounts page, select Create a new account and click Next.

  • [新增帳戶] 頁面上,指定帳戶名稱、描述、郵件伺服器資訊和驗證類型。On the New Account page, specify the account name, description, mail server information, and authentication type. [下一步]Click Next

  • [完成精靈] 頁面上,檢閱要執行的動作,並按一下 [完成] 完成新帳戶的建立。On the Complete the Wizard page, review the actions to be performed and click Finish to complete creating the new account.

使用 Transact-SQLUsing Transact-SQL

使用 Transact-SQL 建立 Database Mail 帳戶To Create a Database Mail account using Transact-SQL

執行預存程序 msdb.dbo.sysmail_add_account_sp 來建立帳戶,並且指定下列資訊:Execute the stored procedure msdb.dbo.sysmail_add_account_sp to create the account and specify the following information:

  • 要建立的帳戶名稱。The name of the account to create.

  • 帳戶的選擇性描述。An optional description of the account.

  • 要顯示於外寄電子郵件訊息的電子郵件地址。The e-mail address to show on outgoing e-mail messages.

  • 要顯示於外寄電子郵件訊息的顯示名稱。The display name to show on outgoing e-mail messages.

  • SMTP 伺服器的伺服器名稱。The server name of the SMTP server.

  • 要用於登入 SMTP 伺服器的使用者名稱 (如果 SMTP 伺服器需要驗證的話)。The user name to use to log on to the SMTP server, if the SMTP server requires authentication.

  • 要用於登入 SMTP 伺服器的密碼 (如果 SMTP 伺服器需要驗證的話)。The password to use to log on to the SMTP server, if the SMTP server requires authentication.

    下列範例會建立新的 Database Mail 帳戶。The following example creates a new Database Mail account.

EXECUTE msdb.dbo.sysmail_add_account_sp  
    @account_name = 'AdventureWorks Administrator',  
    @description = 'Mail account for administrative e-mail.',  
    @email_address = 'dba@Adventure-Works.com',  
    @display_name = 'AdventureWorks Automated Mailer',  
    @mailserver_name = 'smtp.Adventure-Works.com' ;  

待處理:設定 Database Mail 的後續步驟Follow Up: Next Steps to Configuring the Database Mail