Tag Archives: php

Send emails when torrent is done – Windows & uTorrent

Here’s a snippet of PHP code to help you send emails from Windows machine when a torrent has downloaded through uTorrent.
I am using Outlook.com to send and receive email but you can easily use GMail or any other internet mail service.

You will need PHPMailer class

$argOpts = “n:e:”;
$argVal = getopt($argOpts);
$torrent_name = $argVal[‘n’];
$to_email = $argVal[‘e’];
require(“phpmailer/class.phpmailer.php”);
$mail = new PHPMailer();
$mail->Username = “Your outlook.com username”;
$mail->Password = “Your outlook.com password”;
$mail->Host = “smtp-mail.outlook.com”;
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPSecure=”tls”;
$mail->SMTPAuth = true;
$mail->setFrom(“From address”, “From name”);
$mail->addReplyTo(“Reply To address”, “Reply To name”);
$mail->AddAddress($to_email);
$mail->Subject = “Torrent done!”;
$mail->Body = “Finished downloading of \”” . $torrent_name . “\” on ” . date(‘M j, Y @h:i:s a’);
if(!$mail->Send()) {
echo “Mailer Error: ” . $mail->ErrorInfo;
}
else {
echo “Message has been sent”;
}

Save this to sendemailwhentorrentdone.php

You will need to wrap the php script call inside a .bat script for use with uTorrent.

Create uTorrent.bat

php <path>\sendemailwhentorrentdone.php -n %1 -e to_email

Then in uTorrent, go to Options -> Preferences -> Advanced -> Run Program

Enter following in “Run this program when a torrent finishes”

<path>\utorrent.bat “%N”

uTorrent would automatically replace %N with title of torrent.

That’s all you need. From now onwards, your uTorrent client on Windows should be able to send email when a torrent is finished downloading.