in reply to forking() to send e-mail in CGI??

I assume that they are forking because they are actually delivering the mail, rather than queueing it to the mailer on the machine.

If they were using Net::SMTP, and using the smtpsend method, the CGI script would have to do the appropriate DNS lookups, connect to remote MTA ( mail transport agent ), and deliver the mail.

Since this process can take quite a while, you usually don't want your web browser user to have to wait for it. The fork would allow the mailing to run as a separate process, and the web user wouldn't have to wait.

Supposing there's a usable mailer on the web server, I would just queue it there. No need for fork, and you have an intelligent mailer that can retry, etc. See Mail::Mailer or look around for another module that fits your needs.

Replies are listed 'Best First'.
Re: Re: forking() to send e-mail in CGI??
by wazoo (Novice) on Jan 06, 2002 at 02:21 UTC

    Are you talking about a seperate email to every registered user of your forum, every time a post is added? If it is going to be part of the script, where the user adds the post, you need to fork even if you use a local mailer. As your user list grows, you could be generating quite a few emails. Not something your user is going to want to wait for just to reply to a comment.

    Another approach you might want to consider: instead of having it part of the script were the user adds the post, have a seperate maintenance script run at intervals in the background. The maintenance script could check to see if new post had been made (a central file with new post numbers or something else). When the maintenance script finds new posts, it could notify the users by email. This would not only free the poster from waiting for the script to generate mails for everyone on your user list, but the users could get a single email with notification of the posts within a time period instead of several emails as each post is made. I would also suggest that your users be given some way to opt-in or opt-out of your mailings. Registering on a forum that fills your mailbox without warning can be very annoying.

    Chuck