views:

89

answers:

6

I'm writing an application and I'd like it to somehow schedule an email to be sent at a later date (likely an hour after it is run). The programming language will be Python or Java.

Any open-source tools available for that purpose?

EDIT: I forgot to mention it's to be run after a test run, so the application will already be down and I believe the Quartz solution wouldn't work. Would this be possible?

Ideally, I'd like to hear that SMTP protocol has some hidden stuff that allows this, and would just require adding some flag to the message and email providers would interpret as to having to send them later.

+2  A: 

Quartz is a great Java library for functions that you want to run at a certain time, after a certain time interval, etc.

There is also the Timer class in the JDK.

matt b
+5  A: 

Quartz Scheduler can be user for this kind of asynchronous jobs.

Jaydeep
+1 because matt b's 26.4k reputation can live without a +1. :-)
Chris
@Chris If you're aiming for that sort of reputation, keep your comments on-topic. :)
bzlm
The question was edited to say that the JVM may not be running at the time the mails are to be sent.
Thorbjørn Ravn Andersen
+1  A: 

If you are to use Java, try Quartz, an open source job scheduling framework.

chedine
+1  A: 

I don't think standard SMTP protocol has such a feature, so if you want to be platform-independent, you will have to search for another solution.

How about writing your message to a queue (local database, for example) with a timestamp and then have some program watching it periodically and send pending emails out?

Is the delay an exact timedelta or is it "1-2 hours later"? If it is the latter, than you can have an hourly job (cronjob starting every hour or a background job sleeping for an hour), which would then send out the emails.

eumiro
+2  A: 

You can build the actual email to send, using JavaMail (with attachments and all), save it to disk, and then delegate a "mail [email protected] < textfilefromjavamail" to the Linux batch system.

There is an "at" command which will most likely do exactly what you want.

Thorbjørn Ravn Andersen
+1  A: 

Answer 1:

In Python, use threading.Timer to schedule in the future; use smtplib to send an email. No external library needed.

Answer 2:

Sounds like you want the sending program to quit rather than having it wait in the background. You may use cron for this. Alternative just use the unix command sleep and mail:

$ { sleep 3600; echo "hello world" | mail -s the-subject destination-email; } &

P.S. I don't believe SMTP have anything for you in this case. You are really looking for an MTA that has scheduling feature. Though I'm not familiar with it to make a recommendation.

Wai Yip Tung