Jump to content

Event Handler does not send SMTP-AUTH mail (Python)


Recommended Posts

Hi!

 

Some days ago I tried to enable the Retrospect event handler to email me some status reports. To avoid dependancies with the mail client I chose the Python script. Unfortunately (well, actually fortunately) my ISP requires SMTP-AUTH, so I changed the Apple script file accordingly, but no mail was sent.

 

While debugging I copied the Python file, stripped down its code to the bare SMTP functions. It seemed that the smtplib.SMTP call received an error ("No address associated with nodename"), although I was able to access the smtp server (by host name or IP address) with ping, telnet, ...

 

I finally gave up and wrote a PHP script, which accepts the same positional parameters as "macmail.py" and handles the SMTP conversation including the authentication. After changing the corresponding shell statement in the Apple script file, everything works like a charm.

 

Is anybody (!) able to send SMTP-AUTH mails via the Python event handler? I just wonder what went wrong (Mac OS X 10.4.7, Retrospect Desktop 6.1.126) ...

 

Bye, Mattes

Link to comment
Share on other sites

  • 1 month later...

As I was asked in an usenet thread for more details, I decided to post a more detailed description. Maybe some future questions will be answered this way...

 

1.) First I wrote a PHP script to send emails with SMTP-AUTH and let it accept the same positional parameters as the original "macmail.py". I called it "macmail.php" and as I am not able to attach it to this posting, here is the complete script quoted:

 

Code:


 

<?php

 

$to = $_SERVER['argv'][1];

$smtpServer = $_SERVER['argv'][2];

$subject = $_SERVER['argv'][3];

$bodyfile = $_SERVER['argv'][4];

$from = $_SERVER['argv'][5];

$username = $_SERVER['argv'][6];

$password = $_SERVER['argv'][7];

$port = "25";

$timeout = "30";

$localhost = "localhost";

$newLine = "\r\n";

 

$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);

$smtpResponse = fgets($smtpConnect, 515);

if(empty($smtpConnect))

{

$output = "Failed to connect: $smtpResponse";

return $output;

}

 

fputs($smtpConnect, "HELO $localhost" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect,"AUTH LOGIN" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect, base64_encode($username) . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect, base64_encode($password) . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect, "MAIL FROM: $from" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect, "RCPT TO: $to" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect, "DATA" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

$headers = "MIME-Version: 1.0" . $newLine;

$headers .= "Content-type: text/plain" . $newLine;

$headers .= "To: Administrator <$to>" . $newLine;

$headers .= "From: Retrospect Backup <$from>" . $newLine;

$headers .= "Subject: $subject" . $newLine;

$message = file_get_contents($bodyfile);

 

fputs($smtpConnect, "$headers\r\n\r\n$message\r\n.\r\n");

$smtpResponse = fgets($smtpConnect, 515);

 

fputs($smtpConnect,"QUIT" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

 

?>


 

Make sure to remember the location of this script as you will need it in step 3.

 

2.) After that I copied the Python event handler into Retrospect's preference folder and changed its attribute to make it executable ("chmod ugo+x ...").

 

3.) Then I modified the following lines of the event handler: Of course the standard properties to define kMainGroup, kMailServer, kFrom, kUsername, kPassword, but also kScriptCommand (to "/usr/bin/php /.../macmail.php", this must point to the PHP script of step 1). Additional I changed the mail subjects used in the "scriptEnd" paragraph to include the script name into the email subjects (two times: <set mySubject to theScript & ": Execution completed successfully!> and <set mySubject to theScript & ": Retrospect script finished with errors">). In other paragraphs I mount and unmount my backup device, but this is of course not related to the topic of this thread.

 

Voilà ... grin.gif

 

HTH, Mattes

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...