Click here to Skip to main content
15,881,882 members
Articles / Database Development / SQL Server / SQL Server 2012

How to Send Mail Using SQL Server: Part 3

Rate me:
Please Sign up or sign in to vote.
2.93/5 (5 votes)
27 Mar 2016CPOL1 min read 10.7K   8  
In this article, I will explain how to schedule a daily mail from SQL Server 2008.

There are three parts of this tutorial as given below:

  1. Configure email profile and send test Email using SQL Server
  2. Select and send data in mail
  3. Schedule daily mail from SQL Server

Introduction

This article explains how to schedule a daily mail from SQL Server 2008. To send daily email, I will create a SQL Server Agent job to archive mail messages and after sending the mail, I will also recode the Event Logs in a file.

Step 1

Log in to SQL Server 2008 with a correct user name and password.

Step 2

Expand SQL Server Agent, then go to Jobs, then right-click "New Job..." as in the following:

Job in Sql Server

Step 3

The following window appears, click on the General Tab first, then Fill proper data, then click on Steps.

New Job Wizard

Step 4

When you click on Steps, the following window will appear:

Creating Steps in Job

When you click on "New..." it will go to the following window.

New Job Step Wizard

Provide the name of the steps and in the type dropdown, select Transact-SQL Scripts, then select the database and write the following scripts for the command.

SQL
EXEC sp_send_dbmail @profile_name='MyTestMail',  
@recipients='manishki@live.com',  
@subject='My Test Mail Service with student data.',  
@body='Hi This is daily Mail ',  
@body_format ='HTML'  

Step 5

Then click on the OK button, then go to the Schedules tab and you will find the following window:

Schedules in Job

Click on "New...".

Step 6

Then schedule the job by entering the relevant information in the Schedules tab.

New Job Schedule

In this window, set the occurrence, frequency, schedule type, time to fire job, start date and end date and so on.

Then click OK. That's down. Our daily email scheduler is ready and will send mail daily at 08:00PM. Check the mail, it will show the data.

Summary

In this illustration, you learned about configuring and sending daily email using SQL Server 2008. Please provide your valuable comments about this article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
Manish Kumar Choudhary is a passionate and pragmatic software engineer specializing in web application development with ASP.NET MVC, Web API, Entity Framework, NHibernet, Angular, Backbone, HTML5, and CSS. He started programming at the age of twelve on VB.Net and fell in love with it. His dream at the time was to become a software engineer so he pursues programming both academically and professionally. He has a Bachelor of Science in Computer Application and a Master of Science in Computer Application. He has over 3.5 years’ professional experience developing web applications. Outside the software world, he enjoys photography, swimming, cricket and football. Manish is based in Hyderabad, India.

Comments and Discussions

 
-- There are no messages in this forum --