Solved

Using SQL Server 2008  or SQL Server 2008 Reporting Services to build an email notification system

Posted on 2010-11-16
5
250 Views
Last Modified: 2012-06-27
I am building a .NET application for a client that wants to setup an simple email notification subscription system. I plan on building an fairly easy input form to enter the user registration information (email address, etc...). Once they are registered they will have access to the content. The notification system needs to remind the user they have access to the content every 3 weeks before there access expires. How can I do this with SQL Server 2008 or SQL Server Reporting Services?  Where I can send the user an HTML formatted email reminder.  Thanks for any help in advance!!
0
Comment
Question by:encoredatas
  • 3
  • 2
5 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 34152680
>> How can I do this with SQL Server 2008 or SQL Server Reporting Services?

You can use SQL Server 2008 alone to achieve your objective

1. Enable Database Mail in SQL Server 2008 - Make sure that you should have SQL Server edition other than SQL Server 2008 Express.
http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/
2. Create an SQL Server Agent Job with the below tasks.
a. Add a TSQL Step to check for list of members to send email notifications
b. For all those members, capture their email addresses.
c. Configure sending emails to those users via Database email.
d. Schedule this job to run daily

Once done, the users should be receiving notification emails.
Make sure that all necessary logics are included into TSQL Step.
0
 

Author Comment

by:encoredatas
ID: 34152725
I understand steps c and d , but is there an example of how to accomplish steps a and b. Thanks for all the help!
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 34152750
Ok, just a cursor to accomplish the logic in steps a and b and below code can help you out on that.
DECLARE @email_subject nvarchar(1000)
DECLARE @email_body nvarchar(max)
SET @email_body = N'Reminder'
SET @email_body = N'<html><body>Dear {0},<br />Reminder.</body></html>'

DECLARE @email varchar(500);
DECLARE @pbody nvarchar(max)

DECLARE notification_cursor CURSOR FAST_FORWARD FOR
SELECT email, name
FROM ur_table
WHERE isaccess = 1
or last_access_date >= dateadd(ww, -3, getdate())

OPEN notification_cursor
FETCH NEXT FROM notification_cursor INTO @email;

WHILE @@FETCH_STATUS = 0
BEGIN
  SET @pbody = 'some_value'

  EXEC msdb.dbo.sp_send_dbmail
    @profile_name = N'some_profile_name',
    @recipients = @email,
    @subject = @email_subject,
    @body = @pbody,
    @body_format = 'HTML'
  
  FETCH NEXT FROM notification_cursor INTO @Id, @email, @name
END

CLOSE notification_cursor
DEALLOCATE notification_cursor

Open in new window

0
 

Author Closing Comment

by:encoredatas
ID: 34152763
Thanks for the quick response.  This is just what I needed!!
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 34152835
Welcome..
And glad to help you out..
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question