Forum Moderators: mack

Message Too Old, No Replies

Sendmail. Problem with invalid email address

Help required

         

thewyliecoyote

3:55 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



We have a Perl form which uses sendmail to send a confirmation email to an email address entered in the form. However, if the email address is invalid an error is output which appears on the page generated and the "Submit" button is clicked.

How can I prevent sendmail from reporting errors with an email address?

Help very much appreciated.

Romeo

5:49 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



Hi Thewyliecoyote, and welcome here.

There are 2 things to consider:
(1) retracting the ability to send a confirmation mail to arbitrary mail addresses at all, because this may perhaps be misused for spamming, depending on your form of course.
(2) check the mail-address string for a valid syntax before passing it to sendmail.
You may look into this thread for further hints
[webmasterworld.com...]
or browse thru the other results you get when asking Google for
perl validate mail address

HTH and regards,
R.

thewyliecoyote

9:25 am on Jan 28, 2004 (gmt 0)

10+ Year Member



Thanks for the suggestions so far. Our form is generated "on the fly" as part of an ecommerce process so spamming is not an issue. The issue is "is there an option in SendMail that stops it reporting the failure of the email which is sent". We have code which validates the structure of the email address but obviously we can not stop someone making a typing mistake even when they are asked to double enter. If the email address is invalid error messages are issued to Stdout which affect the resulting page presented and details are sent to the dead.letter file.

Romeo

9:13 pm on Jan 28, 2004 (gmt 0)

10+ Year Member



... well, I have not seen such behaviour yet: on my server, when a cgi-script calls sendmail, it never so far got any errors from the background sendmail, and messages to invalid addresses get silently routed to a postmaster's mailbox.
Is your script really writing to sendmail or just doing an exec to a local mail program?

# send mail to $recipient
$mailprog = '/usr/lib/sendmail';
open (MAIL, "?$mailprog $recipient")? die "Can't open $mailprog! $!\n";
print MAIL "From: me\@example.com\n";
print MAIL "To: $recipient\n";
print MAIL ...other stuff ...;
...

You may look at the sendmail's -O options "DeliveryMode" or "ErrorMode" and probably look thru your sendmail.cf config file.

Otherwise, you could indeed try to verify the address the hard way by
-- looking up the MX record of the domain in the DNS
-- open a socket connection on port 25 (SMTP) to the mail server found in MX and
-- start a HELO/EHLO mail conversation
-- entering a RCPT TO: user@domain
and look for any 200 OK or 4xx/5xx reject messages from the target mail server. Depending on the server's spam policy, this may often work and sometimes not.
However, while being there, then you could also deliver the remaining mail body by hand and would not need a sendmail after all ... :-)

Regards,
R.

thewyliecoyote

10:10 pm on Jan 28, 2004 (gmt 0)

10+ Year Member



It will take a couple of days to check what you suggest. Thank you and I will respond when I have experimented further.

Thank you