Wednesday, 10 September 2025

Create account and profile for sending email in SQL Server

Introduction: Hello Guys, “Welcome back” Today, i am here with another one new great article. In this article I explained the implementation about create account and profile for sending emails in SQL Server.

Join our Channel  on Whtsapp and Telagram for All Updates                                          


Creating Account for sending emails in SQL Server

The sysmail_add_account_sp  Store Procedure will be  used to add Account to SQL Server. Through this Store Procedure we will pass necessary parameter which is Mail Server settings as UserName, Password, Port and EnableSsl etc.

Note: It is very compulsory to use the sender’s email address credentials or login details while defining the Gmail SMTP Server Credentials or login details as the sender’s email address must be same as the Gmail Username specified in credentials.

To create an Account for sending emails in SQL Server, just copy and paste and execute the following SQL query, with the editing or modification as per your requirement.

Note: Make sure you entered Gmail SMTP Server Credentials by you will be valid. Find the code for sysmail_add_account_sp Store Procedure below:-

EXEC msdb.dbo.sysmail_add_account_sp

    @account_name = 'SanjeevKumar_Mail_Account'

   ,@description = 'Send emails using SQL Server Stored Procedure'

   ,@email_address = 'youremail@gmail.com'

   ,@display_name = 'Sanjeev Kumar'

   ,@replyto_address = 'youremail@gmail.com'

   ,@mailserver_name = 'smtp.gmail.com'

   ,@username = 'youremail@gmail.com'

   ,@password = 'GMAIL PASSWORD'

   ,@port = 587

   ,@enable_ssl = 1

GO

Creating Profile for sending email in SQL Server

Sends an e-mail message to the specified recipients. The message might include a query result set, file attachments, or both. When mail is successfully placed in the Database Mail queue, sp_send_dbmail returns the mailitem_id of the message. This stored procedure is in the msdb database. The Profile contains information about Account for which the Account needs to be added to a Profile as it is necessary to provide the name of the Profile while sending email using sp_send_dbmail Store Procedure in SQL Server .The sysmail_add_profile_sp Store Procedure is used to create Profile to SQL Server. To create a profile for sending emails in SQL Server, just copy and paste and execute the following SQL query, with the editing or modification as per your requirement

EXEC msdb.dbo.sysmail_add_profile_sp

    @profile_name = 'SanjeevKumar_Email_Profile'

   ,@description = 'Send emails using SQL Server Stored Procedure'

GO

Adding Account to Profile for sending email in SQL Server

The sysmail_add_profileaccount_sp Stored Procedure is used to add Account to Profile. To add account to profile, simply copy, paste, edit (according to your settings) and execute the following SQL query.

EXEC msdb.dbo.sysmail_add_profileaccount_sp

    @profile_name = ' SanjeevKumar_Email_Profile'

   ,@account_name = ' SanjeevKumar_Mail_Account'

   ,@sequence_number = 1

GO

Conclusion: In above code, I have been explained the implementation about to create account and profile for sending emails in SQL Server. This code is very helpful for every developer. Bye Bye and take care of yourself Developers. We will come back shortly with the new article.

Regards

Using Asp.Net

No comments:

Post a Comment