The script used on visibility.i2p
note that all mail request are pushed in database, and launched by a cron job (every 5 mn)
Important!
$from = $row['tofrom']; must be the same as the account (eg tofrom = "
visibility@mail.i2p" cause $username = "visibility";)
<?php
include_once("settings.php");
include_once("lib/configuration.php");
global $CONFIG;
$dbhost = $CONFIG->dbhost;
$dbuser = $CONFIG->dbuser;
$dbpass = $CONFIG->dbpass;
$dbname = $CONFIG->dbname;
$dbport = $CONFIG->dbport;
// Connect to database
if (!$connexion = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport)) {
exit;
}
// Set DB for UTF8
mysqli_query($connexion, "SET NAMES utf8");
$result = mysqli_query($connexion, "SELECT * from {$CONFIG->dbprefix}users_mails");
if ($result) {
while ($row = mysqli_fetch_array($result)){
$id = $row['id'];
$from = $row['tofrom'];
$to = $row['todo'];
$subject = $row['subject'];
$body = $row['body'];
$headers = $row['headers'];
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "127.0.0.1";
$port = "7659";
$timeout = "60";
$username = "visibility";
$password = "xxxxxxxxxxxxxxxxxxxxxxx";
//$localhost = "visibility.i2p"; not needed
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$smtpServer = "192.168.0.xx"; //in case of failure fronm local host
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
}
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
exit;
}
$logArray['connection'] = "Connected: $smtpResponse";
//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
//Say Hello to SMTP
/*fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
*/
//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
//Construct Headers
/*
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $to" . $newLine;
$headers .= "From: $from" . $newLine;
*/ not needed
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$body\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
//nettoyage
mysqli_query($connexion, "DELETE from {$CONFIG->dbprefix}users_mails where id='$id'");
sleep(10);
}
}
mysqli_close($connexion);
?>
don't use it at all, adapt!
Regards