The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

sending e-mails from the web application

I am building a web application in Java. I intend to send e-mails back to the user in several occasions (example- user asks to send the forgotten password e-mailed to him and so on). Should I write code that will attempt to send the e-mail while processing the HTTP request from the user? (and possibly notify him "e-mail sent" or "e-mail failed, try again" types of messages)?

What is the usual practice here?
Newbie 1
Saturday, August 12, 2006
 
 
I can't talk about Java, but I can share with you my PHP experience:
In 90% of web applications I saw emails was sent exactly while processing user HTTP request.
There is also another way. For example, you can store all email information in file or in database while processing user request. Then you will launch cron job (scheduled script) every 5 minutes which will send all queued email messages in background. Main advantage is that you can control mail delivery. If mail can't be sent right now, it will be sent later, in next 5 minutes.
Pavel Vasilevich Send private email
Saturday, August 12, 2006
 
 
It is generally speaking a bad idea to hold up the user while you are sending a message.  The reason is that email can, under certain circumstances, take a while to send or fail definitively.  For example, consider the case of a user who has a graylisting system up -- their mail server will happily ask you to get back to them in five minutes, and your mail server will happily comply, while meanwhile not throwing any errors to Java because they're not yet successful or failed as defined by the RFCs.  For these cases you do not want to keep the user spinning indefinately.  You can do AJAX-y tricks or HTTP refreshes to reload a page and check the status of the email later. 

Alternatively, you can just not tell them anything about the status of the email.  This is actually a good idea for several reasons: #1, it saves you from having to write additional code, #2, it prevents someone from using your send-me-my-password feature as a spam address verifier ("jim@domain.com exists, bob@domain.com exists, sue@domain.com doesn't exist, got it script!  Thanks!") or causing other leakage of privileged data.  (This is the same reason why if your application ever reports "That user doesn't exist" and "Your password was incorrect" as different error messages you've probably done something wrong.)

+1, incidentally, for either an outgoing queue or, since you're using Java anyhow, having a different thread take care of outgoing mail.  You can either use a single daemon thread if you're really anxious about resource use or just create them as you need them (mail is likely to be such a rare operation that you won't even notice the overhead).
Patrick McKenzie Send private email
Saturday, August 12, 2006
 
 
One email is nothing. I would not worry about it.

Years ago I had to send thousands of email from a web page and I went about it all the wrong way. Another programmer came after me and he said I could have just passed an argument to sendmail to queue the request and my web app could have continued but instead I did this thing of writing the request to a file and doing some fork or other ... can't recall. You should be able, if necessary, to tell your MTA to take the request and your script can continue with minimal loss of time.
curdDeveloper
Thursday, August 17, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz