Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redeliver message from user's mailbox 1

Status
Not open for further replies.

fugtruck

MIS
Jul 1, 2009
62
0
0
US
I have a Postfix + SpamAssassin server acting as an outbound SMTP gateway to prevent my users from sending spam. Messages that have a high enough SPAM score get delivered to a local user account designated as spam. Well, I have a problem and some messages were incorrectly scored and got sent to the spam mailbox. I have since fixed the problem and need to redeliver these messages, but they are no longer available from the client (the messages were actually generated from a form on a web site) and the only copies I have are the ones in the spam mailbox. I tried the following command:

sendmail -i < message_file_name

but nothing shows up in the mail log indicating that the message was ever sent. I also need the messages to appear as they were originally sent (hopefully) and there are a lot of them, so just forwarding individual messages is not going to work.

Any suggestions?
 
Perhaps a long shot, but are you using Amavisd with postfix + spamassassin and if so, did the messages go to a quarantine directory in addition to being sent to the spam folder?

If it is in a quarantine file, you can use the amavisd-release command to re-inject the message back into the delivery queue.



 
Nope, not using Amavisd. Been meaning to reconfigure the server with it but haven't gotten around to it
 
It is a bit of a work around, but perhaps you could use a PHP script to read the emails, which should be text files, extract the recipient information and re-send it out. The PHP Pear libraries have rather comprehensive mail support that is straight forward to use.

Here is some code that is modified from a web page I am working on to get you started. You would need to read the file and use a regex pattern match and find the recipient information and then build up the email from the one in the spam folder.

Code:
	$fp = fopen($outfile, "r");
	if(!$fp || filesize ($outfile)==0)
	{
		$result = -1;
	}
	else
	{
		//read the encrypted file
		$contents = fread ($fp, filesize ($outfile));
		//delete the encrypted temp file
		unlink($outfile);

 		$from = "webpage <webpage@localhost>";
 		$to = "xxx < xxx@nyyyy.net>";
 		$subject = "abcd";
 		$date = date("d m Y : H:i:s", time());
 		$host = "your.smtp.server";
 		$username = "authenticated user name";
 		$password = "password here";
		 
 		$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject, 'Date' => $date);
 		$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username,
 		'password' => $password));
 
		 $mail = $smtp->send($to, $headers, $contents); //was body - changed to contents
 
		 if (PEAR::isError($mail)) 
		 {
   			echo("<p>" . $mail->getMessage() . "</p>");
  	 } 
  	 else 
  	 {
   			echo("<p>Message successfully sent!</p>");
  	 }
		
	}
}
 
Your quite welcome. I hope your successful in the attempt.

Just make sure you work from a backup copy of the spam folder, just in case. When writing scripts that open and write to the files, you can easily delete things
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top