Configure SQL Server Database Mail

This article shows the step by step approach to Configure SQL Server Database Mail to send Emails using your Gmail account or any other account. To Configure, Please select the Management Folder within the SQL Server Object Explorer, and then select Database Mail.

Open Management Studio Object Explorer 1

Right-click on the Database Mail will open the context menu. Please select the Configure Database Mail option to create new or to View, Edit, and Delete existing Database Mails in SQL Server.

In SQL Server Object Explorer, Choose Configure Database Mail option 2

Once you select the SQL Server Configure option, a new wizard will open.

Configure SQL Server Database Mail Wizard Welcome Page 3

Configure SQL Server Database Mail

Select Configuration Task: This page is used to create or Manage Database Mails. In this example, we want to configure a new mail. So, please select the Setup Database Mail by performing the following tasks option

Select Configuration Task 4

New Profile: This page is to create a new profile and to add the SMTP account to configure SQL Server Database Mail. From the below screenshot, you can see that we assigned Email as the profile name, and This is an Email Configuration as the profile description. Next, click on the Add button to add a new SMTP account to this profile.

Add SMTP Account to Configure SQL Server Database Mail 5

Once you click on the Add button, a new window will pop up to configure SQL Server Database Mail.

  • Account Name: A unique name for this SMTP account.
  • Description: Valid description for the above-specified account
  • Email Address: Email Id that you want to use for sending an Email. Senders Email Address.
  • Display Name: This name is displayed within the sent email.
  • Reply Email: same as Email Address.
  • Server Name: valid SMTP name. If you are using Gmail, then use smtp.gmail.com, and for Windows live accounts, use smtp.live.com, etc.
  • Port Number: By default, you can use Port number 25, but for Gmail SSL, please use 587.

Next, under the SMTP Authentication section, you have to configure the Authentication details for SQL Server Database Mail.

  • Windows Authentication: It will use the Windows credentials
  • Basic Authentication: Always use this option. Here please specify the sender’s Email ID and password.
  • Anonymous Authentication: It will not use any authentication
Create a New SQL Server Database Mail Account 6

From the below screenshot, you can see that we assigned MSBI as the account name, This is a Gmail Account as the description, and Suresh as the display name.

Configure SQL Server Database Mail 7

After you click OK, the SMTP account creation form will close.

Add Profile Name and Description 8

If it is your default profile, select Yes otherwise, please leave the option to default No.

Set the Default Profile 9

Click the Next button.

Configure System Parameters 10

Click on the Finish button to finish Configure SQL Server Database Mail to send emails.

Complete the Wizard by clicking the Finish Button 11

Lastly, it will display the details. Please click on the Close button to close the SQL Server Database Mail Configuration wizard.

Click the Close button 12

Now right-click on the Database Mail will open the context menu. This time, Please select Send Test EMail.. option to send an Email using the SMTP account that we created earlier.

From Object Explorer choose Send Test E-Mail 13

Add the email address, and Change the Subject and Message Body as per your requirements. And after you complete editing, Please click the Send Test Email button to send an Email.

Click the Send Test E-Mail option 14

Let me open My Gmail account.

Open Gmail 15

Delete Database Mail

To delete the configured SQL Server database Email, Right-click on the Database Mail will open the context menu. Please select the Configure Database Mail option to open the wizard. And in the second Page, please select the Manage Database Mail accounts and profiles option this time.

Configure SQL Server Database Mail 16

Manage Profiles and Accounts: Use this page to Create, View, Edit, or delete the Configured Database Mail accounts and profiles.

  • Create a new account: This option is used to create a new one.
  • View, Change, or Delete an existing account: As its name suggests, we can view, edit or delete existing ones.
  • Create a new profile: Use this option to create a new profile.
  • View, Change, or Delete an existing profile: As its name suggests, we can view, edit, or delete existing profiles.

Before you start deleting, you have to delete the profiles linked to that account. So, we are selecting the last option to delete the profile.

Select View, Change, or Delete an existing profile option 18

From the drop-down list, please select the Profile Name and click the Delete button to delete the profile.

Click the Yes Button 19

After deleting the profile, please select the second option to delete the Configured SQL Server Database Mail account

Choose View, Change, or Delete an existing account 17

Or you can use the following SQL Query to delete

EXECUTE msdb.dbo.sysmail_delete_account_sp 
 @account_name = 'MSBI' ;
Categories SQL