Forum email not working

Web discussions, including project website, forums, wiki, and others.
Post Reply
VCL
Peon
Peon
Posts: 4
Joined: Sat Sep 25, 2004 6:04 pm

Forum email not working

Post by VCL » Tue Mar 01, 2005 10:39 pm

As you may have noticed, forum email stopped working a month ago. SourceForge made webserver applications unable to send mail to prevent spam abuse. Projects must now queue email in the database, and run an application on the shell server which periodically downloads email from the queue, and then send it.

I modified the OpenKore forums to do this. I can send you the code if you like.
User avatar
Bjørn
TMW Adviser
TMW Adviser
Posts: 1430
Joined: Thu Dec 09, 2004 7:50 pm
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn » Wed Mar 02, 2005 11:24 am

But we're using phpBB. If you think your modifications apply to us as well then feel free to send it, and we'll look into it.
User avatar
maci
Warrior
Warrior
Posts: 507
Joined: Sun Dec 05, 2004 9:01 pm
Location: Germany
Contact:

Post by maci » Wed Mar 02, 2005 12:40 pm

shouldnt be that hard to implent this
ElvenProgrammer wrote:Maci: don't be rude, we're here to help people ;)
VCL
Peon
Peon
Posts: 4
Joined: Sat Sep 25, 2004 6:04 pm

Post by VCL » Thu Mar 03, 2005 6:04 pm

But we're using phpBB.
So am I. :roll:

phpBB sucks at posting code because it destroys tabs. Anyway...

You will need the following MySQL table:

Code: Select all

CREATE TABLE mailer (
   id INT UNSIGNED AUTO_INCREMENT,
   mailto VARCHAR(255) NOT NULL,
   subject VARCHAR(255) NOT NULL,
   body TEXT NOT NULL,
   extra_headers TEXT NOT NULL,
   PRIMARY KEY (id)
);
In includes/emailer.php, add the following function to the class:

Code: Select all

function savemail($db, $to, $subject, $body, $extra_headers)
	{
		$sql = sprintf("INSERT INTO mailer VALUES(NULL, '%s', '%s', '%s', '%s');",
			mysql_escape_string($to),
			mysql_escape_string($subject),
			mysql_escape_string($body),
			mysql_escape_string($extra_headers)
			);
		$db->sql_query($sql);
		return 1;
	}
In send(), look for:

Code: Select all

$result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
Replace with:

Code: Select all

$result = $this->savemail($db, $to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers);
In your shell server's home folder, save the following script as mailer.pl:

Code: Select all

#!/usr/bin/perl -w
use strict;
use DBI;
use Net::SMTP;

my $smtp = 'mail.sourceforge.net';
my $mailfrom = 'themanaworld@themanaworld.sourceforge.net';

my $database = 'themanaworld';
my $user = 'themanaworld';
my $pass = 'your password';
my $host = 'mysql.sourceforge.net';
my $table = 'mailer';

my $dbh=DBI->connect("DBI:mysql:$database:$host", $user, $pass);

my $sql = "SELECT * FROM $table;";
my $sth = $dbh->prepare($sql);
my $rc = $sth->execute;

my @mails;
while (my @r = $sth->fetchrow_array) {
	push @mails, \@r;
}
$dbh->do("TRUNCATE TABLE $table");

my $i = 1;
foreach my $r (@mails) {
	print "Sending mail $i of " . @mails . "...\n";
	my %mail = (
		'To' => $r->[1],
 		'From' => $mailfrom,
		'Subject' => $r->[2],
		'Message' => $r->[3],
		'X-Mailer' => "Openkore Forum Mailer v0.1"
	);
	sendmail(\%mail);
	$i++;	
}

sub sendmail {
	my $mail = shift;

	my $smtp = Net::SMTP->new($smtp);
	$smtp->mail($mail->{From});
	$smtp->to($mail->{To});
	$smtp->data();
	$smtp->datasend("Subject: $mail->{Subject}\n");
	$smtp->datasend("X-Mailer: $mail->{'X-Mailer'}\n");
	$smtp->datasend("From: $mail->{From}\n");
	$smtp->datasend("To: $mail->{To}\n");
	$smtp->datasend("\n");
	$smtp->datasend("$mail->{Message}\n");
	$smtp->dataend();
	$smtp->quit;
}
Remember to set the password!


Although you're supposed to send the email in a cron job, cron doesn't work because crond is not running! So I wrote a little script that runs mailer.pl every 30 minutes.
Save as mdaemon.pl:

Code: Select all

#!/usr/bin/env perl
# cron doesn't work, bah
use strict;
use POSIX;

if (fork() == 0) {
	POSIX::setsid();
	open(STDIN, "< /dev/null");
	open(STDOUT, "> /dev/null");
	open(STDERR, "> /dev/null");
	while (1) {
		system('perl', '/full/path/to/mailer.pl');
		sleep(30 * 60);
	}
	POSIX::_exit(0);
}
Remember to set the full path to mailer.pl!
Type: mdaemon.pl
Then exit. mdaemon.pl will continue to run in the background.
User avatar
Bjørn
TMW Adviser
TMW Adviser
Posts: 1430
Joined: Thu Dec 09, 2004 7:50 pm
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn » Wed Jun 01, 2005 1:08 pm

Well, I finally made these modifications and ran the script. I hope it'll work.
User avatar
Bjørn
TMW Adviser
TMW Adviser
Posts: 1430
Joined: Thu Dec 09, 2004 7:50 pm
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn » Sun Oct 02, 2005 10:07 pm

Well this script had to be disabled again after we moved to the new server of course. Maybe now the emails will start rolling finally. Did we really miss them? :-)
User avatar
maci
Warrior
Warrior
Posts: 507
Joined: Sun Dec 05, 2004 9:01 pm
Location: Germany
Contact:

Post by maci » Sun Oct 02, 2005 10:13 pm

i missed them :P
ElvenProgrammer wrote:Maci: don't be rude, we're here to help people ;)
xand
Peon
Peon
Posts: 95
Joined: Tue Jul 19, 2005 7:08 pm

Post by xand » Sun Oct 02, 2005 11:33 pm

me too :evil:
Post Reply