Solved

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

Posted on 2010-11-16
5
247 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now