Click here to Skip to main content
15,889,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a table that has 25 records of employees.No I want that each monday a mail is to to be send to all employees through sql server by stored procedure or something else.

Please help me.

Thanks
Mohd wasif
Posted

SQL Server 2005 Database Mail provides several options for sending e-mail messages. These options include sending attachments, setting sensitivity and importance, including query results, and formatting the e-mail message in an HTML format. You can set up using the link http://www.techrepublic.com/article/setting-up-database-mail-in-sql-server-2005/6161839[^]

Here is the sample SQL code to send mail:

SQL
EXEC msdb.dbo.sp_send_dbmail
 @recipients=N'chapman.tim@gmail.com',
@body='Message Body', 
 @subject ='Message Subject',
@profile_name ='Database-mailProfile',
@file_attachments ='C:\FileAttachment.txt';
 
Share this answer
 
SQL
CREATE PROCEDURE [dbo].[sp_send_mail] 
@From varchar(100),
@To varchar(100),
@Subject varchar(100),
@Body varchar(4000),
@CC varchar(100) = null,
@BCC varchar(100) = null
AS
Declare @MailID int
Declare @hr int
EXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUT
EXEC @hr = sp_OASetProperty @MailID, 'From',@From
EXEC @hr = sp_OASetProperty @MailID, 'Body', @Body
EXEC @hr = sp_OASetProperty @MailID, 'BCC',@BCC
EXEC @hr = sp_OASetProperty @MailID, 'CC', @CC
EXEC @hr = sp_OASetProperty @MailID, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @MailID, 'To', @To
EXEC @hr = sp_OAMethod @MailID, 'Send', NULL
EXEC @hr = sp_OADestroy @MailID



Get a good example on cp: SQL SERVER - 2008 - Configure Database Mail - Send Email From SQL Database[^]
 
Share this answer
 
Comments
Mohd Wasif 15-Mar-12 8:40am    
I have done this but I am not receiving mail in my mail box.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900