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
You can build the actual email to send, using JavaMail (with attachments and all), save it to disk, and then delegate a "mail foo@bar.com < textfilefromjavamail" to the Linux batch system.
There is an "at" command which will most likely do exactly what you want.
Quartz Scheduler can be user for this kind of asynchronous jobs.
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.
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.
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.
If you are to use Java, try Quartz, an open source job scheduling framework.