Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/Code)
 MOD: E-mail on insert of unmoderated message v1.0
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

sumo
Junior Member

USA
121 Posts

Posted - 12 November 2001 :  16:47:33  Show Profile  Visit sumo's Homepage  Send sumo an AOL message
Name: E-mail on insert of unmoderated message
Version: 1.0
Snitz Version: 3.303
Database Type: SQL Server 7.0/2000
Author: Michael Sumerano
Support: MOD support forum
Install: Must have Query Analyzer or Enterprise Manager access to your SQL server. Must have the SMTP Service installed on the same server as your SQL Server OR use a different SMTP component like ASPEmail.

This MOD is NOT a mod of the Snitz forum code, but an addition to the SQL Server forum database, specifically to the FORUM_TOPICS and FORUM_REPLY tables. The following code will set up two triggers, one on each of the tables mentioned above that will e-mail moderators of a forum when an unapproved topic or reply is posted. This modification has been invaluable to our company since there is nowhere in the code to actually notify a moderator when unapproved messages appear in their forums.

[1] The first modification is a stored procedure in your MASTER database that will perform the actual sending of the e-mail. This code is basically pulled from SQLTeam.com. Mine uses Microsoft's SMTP service and the CDONTS.NewMail component, but you can use any SMTP component. Just change the code to set the properties that are specific to the SMTP component you are using.

Create Procedure sp_SMTPMail

@SenderAddress varchar(100),
@RecipientAddress varchar(100),
@Subject varchar(200),
@Body varchar(8000)

AS

SET nocount on

declare @oMail int --Object reference
declare @resultcode int

EXEC @resultcode = sp_OACreate 'CDONTS.NewMail', @oMail OUT

if @resultcode = 0
BEGIN
EXEC @resultcode = sp_OASetProperty @oMail, 'From', @SenderAddress
EXEC @resultcode = sp_OASetProperty @oMail, 'To', @RecipientAddress
EXEC @resultcode = sp_OASetProperty @oMail, 'Subject', @Subject
EXEC @resultcode = sp_OASetProperty @oMail, 'Body', @Body
EXEC @resultcode = sp_OAMethod @oMail, 'Send', NULL
EXEC sp_OADestroy @oMail
END

set nocount off
GO


[2] The next modification is to add a trigger to the FORUM_TOPICS table. This will actually "trigger" the e-mail event when an unmoderated topic is inserted into the FORUM_TOPICS table. Make sure to change the @From variable to the e-mail address that you want the e-mail to come from.

CREATE TRIGGER tr_FORUM_TOPICS_INSERT
ON dbo.FORUM_TOPICS
FOR INSERT
AS
IF (SELECT T_STATUS FROM inserted WHERE T_STATUS = 2) = 2
BEGIN
DECLARE EmailModerators CURSOR FOR
select t.topic_id, m_email, c.cat_name, f.f_subject
from inserted t
inner join forum_moderator mo on t.forum_id = mo.forum_id
inner join forum_members me on mo.member_id = me.member_id
inner join forum_category c on t.cat_id = c.cat_id
inner join forum_forum f on t.forum_id = f.forum_id
DECLARE @From varchar(255)
DECLARE @Topic_Id int
DECLARE @To varchar(255)
DECLARE @CatName varchar(255)
DECLARE @ForumName varchar(255)
DECLARE @Subject varchar(255)
DECLARE @Body varchar(8000)

SET @From = 'you@yourdomain.com'
SET @Subject = 'NEW, UNMODERATED topic in Your Forum'

OPEN EmailModerators
FETCH NEXT FROM EmailModerators INTO @Topic_Id, @To, @CatName, @ForumName

WHILE @@FETCH_STATUS = 0
BEGIN
SET @Body = 'An unapproved topic has been posted in the ' + @ForumName + ' - ' + @CatName + ' forum. Please visit the forum and APPROVE, HOLD, or DELETE the message. ' + 'http://yourdomain.com/forum/link.asp?TOPIC_ID=' + cast(@Topic_Id as varchar(255))
exec sp_SMTPMail @From, @To, @Subject, @Body
FETCH NEXT FROM EmailModerators INTO @Topic_Id, @To, @CatName, @ForumName
END
CLOSE EmailModerators
DEALLOCATE EmailModerators
END


[3] The last modification is to add a trigger to the FORUM_REPLY table. This will actually "trigger" the e-mail event when an unmoderated reply is inserted into the FORUM_REPLY table. Make sure to change the @From variable to the e-mail address that you want the e-mail to come from.

CREATE TRIGGER tr_FORUM_REPLY_INSERT
ON dbo.FORUM_REPLY
FOR INSERT
AS
IF (SELECT R_STATUS FROM inserted WHERE R_STATUS = 2) = 2
BEGIN
DECLARE EmailModerators CURSOR FOR
select r.topic_id, me.m_email, c.cat_name, f.f_subject
from inserted r
inner join forum_moderator mo on r.forum_id = mo.forum_id
inner join forum_members me on mo.member_id = me.member_id
inner join forum_category c on r.cat_id = c.cat_id
inner join forum_forum f on r.forum_id = f.forum_id
DECLARE @Topic_Id int
DECLARE @To varchar(255)
DECLARE @From varchar(255)
DECLARE @CatName varchar(255)
DECLARE @ForumName varchar(255)
DECLARE @Subject varchar(255)
DECLARE @Body varchar(8000)

SET @From = 'you@yourdomain.com'
SET @Subject = 'NEW, UNMODERATED reply in Your Forum'

OPEN EmailModerators
FETCH NEXT FROM EmailModerators INTO @Topic_Id, @To, @CatName, @ForumName

WHILE @@FETCH_STATUS = 0
BEGIN
SET @Body = 'An unapproved reply has been posted in the ' + @CatName + ' - ' + @ForumName + ' forum. Please visit the forum and APPROVE, HOLD, or DELETE the message. ' + 'http://yourdomain.com/forum/link.asp?TOPIC_ID=' + cast(@Topic_Id as varchar(255))
exec sp_SMTPMail @From, @To, @Subject, @Body
FETCH NEXT FROM EmailModerators INTO @Topic_Id, @To, @CatName, @ForumName
END
CLOSE EmailModerators
DEALLOCATE EmailModerators
END


More info to follow based on any questions!

Mike
http://www.ekeystone.com/
http://www.sumovw.com/
http://www.driverfx.com/

sumo
Junior Member

USA
121 Posts

Posted - 14 November 2001 :  14:19:32  Show Profile  Visit sumo's Homepage  Send sumo an AOL message
Wow. No comments. I have stunned the crowd.



Mike
http://www.ekeystone.com/
http://www.sumovw.com/
http://www.driverfx.com/
Go to Top of Page

sumo
Junior Member

USA
121 Posts

Posted - 30 November 2001 :  15:37:23  Show Profile  Visit sumo's Homepage  Send sumo an AOL message
I have made some changes to this to pull out information needed in the e-mail from the config table, but I'm having some trouble with the body string that is concactinated. It keeps getting truncated when I use a variable for the forum URL rather than just type it in. I'll post the update once I have it finished.

BTW, is ANYONE else using this?

Mike
http://www.ekeystone.com/
http://www.sumovw.com/
http://www.driverfx.com/
Go to Top of Page

kaborka
Starting Member

18 Posts

Posted - 08 December 2001 :  17:03:42  Show Profile
sumo: I had made a posting a while back in one of the other forums asking for just this feature. This is exactly what I need, and it is a very clean solution. You made my day. Thank you very much for your contribution.

Go to Top of Page

sumo
Junior Member

USA
121 Posts

Posted - 09 December 2001 :  10:09:59  Show Profile  Visit sumo's Homepage  Send sumo an AOL message
You are quite welcome. There are more improvements that I've made locally to that so nothing would need to be changed in it. Just drop 'em in and go, but part of it isn't working properly, most likely because of a bug in SQL 7.0 and string concatenation. Once I figure it out, I'll post the new version of them. Basically, all they do is query the form database for the variables that I hardcoded in there (i.e. the forum name and the URL). I was hoping to make those changes and add it as a downloadable mod on the mod resource, but no luck yet.

BTW, you also have to thank SQL Team for providing the SMTP mailing code and help with triggers!

quote:

sumo: I had made a posting a while back in one of the other forums asking for just this feature. This is exactly what I need, and it is a very clean solution. You made my day. Thank you very much for your contribution.



Mike
http://www.ekeystone.com/
http://www.sumovw.com/
http://www.driverfx.com/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.23 seconds. Powered By: Snitz Forums 2000 Version 3.4.07