| |||||||||||
| |||||||||||
Emailing from a Perl program Posted by enquirer (enquirer), 8 August 2002 An enquirer by email wrote:In the following context is it also possible to generate a email if a file cannot be opened open (FILEHANDLE, "/file/location/somename.txt") || die "Problem with file opening - $!" Can I put something on the end like a shell script statement && (echo "From: a_user@email.com"; echo "Subject: Something"; mail a_anotheruser@.email.com) So in essence it would look like: open (FILEHANDLE, "/file/location/somename.txt") || system (echo "From: a_user@email.com"; echo "Subject: Something"; mail a_anotheruser.email.com) && die "Problem with file opening - $!" Posted by admin (Graham Ellis), 8 August 2002 Yes - you can get the server to send you an email - sample code follows. One of the things that does vary from server to server is which email programs are available, and where they're located; my example uses the most common location for Linux / Unix boxes. I have also added a nice error message for the user, rather than have them get the default "Internal Server Error 500" message.Code:
Posted by John_Moylan (John_Moylan), 10 August 2002 I have seen many people send mail by piping to sendmail(or whatever) as Grahams example.But there are some Modules that can help, Mail::Mailer being the one that I regularly use. Code:
(Sorry about the bad code formatting above, its a bit difficult when using the BB's code tags, but I hope you get the idea.) I usually create a function wrapper for the Module to simplify calling it, but it's a nice clean way if your sending multiple emails from a program, and it handles 'CC & BCC' nicely too. http://search.cpan.org/author/MARKOV/MailTools-1.48/Mail/Mailer.pm jfp Posted by John_Moylan (John_Moylan), 10 August 2002 Oh, and on the subject of this thread, I mainly used this to have the server mail me if it encountered errors.Didn't want to be seen a moving "off topic" This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |