Jump to content

Python Script email event handler


Recommended Posts

This is an unsupported update to the Retrospect Email Event Handler. It has been modified to use a python script to send mail instead of Mail.app.

 

 

 

Read me:

 

 

 

This Retrospect Event Handler consists of two pieces, "Retrospect Event Handler", and "macmail.py".

 

 

 

Copy Retrospect Event Handler and macmail.py to /Library/Preferences/Retrospect, and edit Retrospect Event Handler to contain the right values for your mail server, SMTP authentication (if you use it), and to and from addresses.

 

 

 

You shouldn't have to edit macmail.py at all. If you wish to copy macmail.py to a different location on the system, you can do so, but you need to edit the kScriptCommand property in Retrospect Event Handler to point to the new location.

 

 

 

For use with Retrospect 5.1 and 6.0.

 

Mac OS 10.2.8 or later

 

Filename: pyRetro-0.5.sit

 

 

 

This attachment was updated on 7/29/04

 

 

Link to comment
Share on other sites

  • 3 months later...

Hi,

 

Your python script works great for me, but I've had no luck in adding an additional recipient. I placed each address inside quotation marks with a comma in between. Is that correct? Have you tried multiple recipients?

 

I had the same problem with the script which uses the Mail application so the problem might be in the event handler script. Do you have any ideas on what I might do to resolve this?

 

Thanks for the help.

Link to comment
Share on other sites

  • 4 weeks later...

This rocks! Previously I had tried to use the mail.app script and had not been able to get it to send messages out (blank recipients), but now I don't even need Mail open!!!!

On a side-note, how is editing the script in the Mac OS X 10.2 and the Mac OS X 10.3 version of script editor different? I've done both and something about the way 10.3's editor saves it makes it not work with Retrospect 5.0238.

Thanks.

Link to comment
Share on other sites

  • 3 weeks later...

I think there is a "bug" in the python script.... It is missing a return ret at the end of the auth_send_mail( routine. I'm not a python expert so I may be wrong, but it seems wrong to me and putting it in fixed an issue I was having.

 

----- This ----

def auth_send_mail(server, to, frum, subject, body_file, user, passwd):

srv = None

ret = True

try:

srv = smtplib.SMTP(server)

except:

ret = False

return ret

 

try:

srv.login(user, passwd)

except smtplib.SMTPAuthenticationError:

ret = False

return ret

 

try:

srv.sendmail(frum, to, build_message(frum, to, subject, body_file))

except:

ret = False

return ret

 

if __name__ == "__main__":

import sys

 

----- Should be -----

 

def auth_send_mail(server, to, frum, subject, body_file, user, passwd):

srv = None

ret = True

try:

srv = smtplib.SMTP(server)

except:

ret = False

return ret

 

try:

srv.login(user, passwd)

except smtplib.SMTPAuthenticationError:

ret = False

return ret

 

try:

srv.sendmail(frum, to, build_message(frum, to, subject, body_file))

except:

ret = False

return ret

return ret

 

if __name__ == "__main__":

Link to comment
Share on other sites

  • 2 months later...

Today we uploaded a new version of this script:

 

 

Attached is a new release of the Python event handler. It includes the following changes.

 

- Added debugging support. This can be enabled by editing macmail.py, and setting DEBUG=True. This will create /tmp/macmail.py.log, and log the SMTP session to it.

 

- Added missing 'return ret' in auth_send_mail, this was causing mails not to go out to multiple users when using SMTP authentication.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

The script is an AppleScript application; it gets launched by Retrospect but it's running (or, in your case not running) independantly.

 

 

- Can you double-click it on its own, without Retrospect running?

- Can you bring back the original, un-configured version and run that?

- Can you open it in ScriptEditor and run it there?

- Can you Save As... as another file and run that one?

 

 

Hmmm

 

Dave

Link to comment
Share on other sites

The app runs fine on it's own. The original version also produces the same "Type 1" error.

 

If you run the app independently or inside the Script Editor everything appears OK. I believe it just sits there waiting for Retrospect to call it into action.

 

With that assumption, it appears that the script sits there after booting Retrospect. I then choose 'Start Backup Server'. Retropsect does it's little getting started routine. Then the script starts spitting out the "type 1" error.

 

Again, this happens both with the stock script and the newest one.

Link to comment
Share on other sites

I've got this script installed, and seems to be working. Sends me notifications during the start of a script, as well as the completed log file.

 

However, it does not seem to send an email when media is needed. Retrospect will be prompting for the next tape, however, an email is never sent despite being set in the Event Handler script.

 

 

Any thoughts?

Link to comment
Share on other sites

  • 2 months later...

This tread has been beaten to death on here but I am at a dead-end on this one.

 

I can't get the python script to work. My event handler has a STMP host, and a 'all events' address specified.

 

I lauch Retrospect (the event handler launches) and...

- run a script and no emails are sent at all

- My local system and mail logs show no activity at all

- a /tmp/macmail.py.log file is created but is empty

- /tmp/macmail.message is created

- the system / mail logs on my STMP server show no access attemps or failures

- the same goes for the firewall logs (port 25 is wide open on all systems)

 

I had this working at one point but I have no idea what has changed to break this. Perhaps python is the problem???

 

Dan T

Link to comment
Share on other sites

  • 2 weeks later...

Hi

 

I have had similar results when I mucked around with the content of the macmail.py file. Applescript would get called but nothing happend after that.

 

I went back to the base macmail.py and it worked. Out of curiosity, do the mail.app event handlers work for you?

 

Thanks

Nate

Link to comment
Share on other sites

  • 1 month later...

I am using the base script and I have not edited it at all.

 

I have the same issue on a second machine. Both are running OS X 10.3.5 Server. Same problem - the scripts run but no email is sent or even attempted to be sent (i.e.no log activity). All that happens is some temp files are created in /tmp/. These files contain what looks like the message body but the actual sending on the mail fails.

 

I have not tried the mail.app method. I am baffled why this is not simply a built in feature of Retrospect rather than an AppleScript monitoring an application and then passing data to a third app for mailing!

 

Dan T

Link to comment
Share on other sites

I just turned it on 'DEBUG=True'.

 

Here are my files:

 

xserve:/Library/Preferences/Retrospect root# ls -al

total 4896

drwxrwxr-x 11 admin admin 374 7 Dec 13:31 .

drwxrwxr-x 20 root admin 680 7 Dec 08:57 ..

-rw-rw-r-- 1 admin admin 6148 28 Oct 10:05 .DS_Store

-rw-rw---- 1 admin admin 3379 2 Dec 02:53 Backup Report

-rwsrwxr-x 1 root admin 141060 6 Oct 12:10 LaunchRetroHlper

-rw-rw---- 1 root admin 2055038 7 Dec 08:58 Operations Log

-rw-rw---- 1 root admin 160008 7 Dec 08:57 Retro.Config (6.0)

-rw-rw---- 1 root admin 6500 30 Nov 23:50 Retro.Icons (6.0)

-rwxrwxrwx 1 admin admin 9116 7 Dec 08:58 Retrospect Event Handler

-rwxrwxrwx 1 admin admin 1743 7 Dec 13:32 macmail.py

-rw-rw---- 1 root admin 585 7 Dec 08:58 retrorunfile

 

I will try a manual script and report back.

 

Dan T

Link to comment
Share on other sites

  • 7 months later...

Hi all

 

I've just installed the trial version of Retrospect Desktop Mac and the python script is not working for me either. I'm having exactly the same results as jasper502.

 

- run a script and no emails are sent at all

- My local system and mail logs show no activity at all

- a /tmp/macmail.py.log file is created but is empty

- /tmp/macmail.message is created

- the system / mail logs on my STMP server show no access attemps or failures

- the same goes for the firewall logs (port 25 is wide open on all systems)

 

Also tried to chmod 775 macmail.py but that doesn't seem to help.

 

Has anyone figured out how to resolve this issue?

 

Thanks,

Link to comment
Share on other sites

  • 5 months later...

There is a bug in the Applescript, sender and recipient addresses are not quoted when the mailer script is called :

do shell script kScriptCommand & space & toaddress & space & kMailServer & space & quoted form of subj & space & POSIX path of target_file & space & kFrom & space & kUsername & space & kPassword

 

If email addresses of the form "Real Username <user@somdomain.com>" are used, then the result is < and > characters in the command line as well as additional spaces. The result is a command line that is not as intended :

 

/usr/bin/python /Library/Preferences/Retrospect/macmail.py Real Username <user@somdomain.com> mail.server.domain ........

 

Some additional quotes are required to turn this into :

 

/usr/bin/python /Library/Preferences/Retrospect/macmail.py "Real Username <user@somdomain.com>" mail.server.domain ........

 

So the script line should be :

 

do shell script kScriptCommand & space & quote & toaddress & quote & space & kMailServer & space & quoted form of subj & space & POSIX path of target_file & space & quote & kFrom & quote & space & kUsername & space & kPassword

 

thus quoting both the sender and recipient email addresses.

 

There are two kinds of shell programmer - those that have already missed out required quotes, and those that haven't written any code yet ! doh.gif

Link to comment
Share on other sites

In the past, I've been using the Apple Mail program and Retrospect Event Handler to send me backup logs, but it doesn't seem to work with the Mac OS X 10.4 version of Mail. So I found this Python script replacement and it is working just fine on all my Macs running 10.3 or 10.4 -- except one. The one in question is running Server 10.3.9 with Retrospect Workgroup 6.1 and the latest driver update. I've followed the instructions as listed above about modifying the AppleScript file to include the extra quote commands but it hasn't fixed it either. Is there something extra I have to do with the Server edition of 10.3 to get this to work? If so, does this also apply to Server 10.4, as I'm planning on upgrading to that within the next couple of months.

Link to comment
Share on other sites

As you say, you had to "fool around a bit to get the mail stop/start stuff working" -- is this something I'd likely have to do under Server 10.3.9? I don't have any real awareness of how Python works -- all I did was configure the AppleScript and put the files in the right place. So if there was any extra adjustments you can remember you had to do, I'd like to know if you can recall what they were... maybe they're what I need to do?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...