Home > Archive > PERL Beginners > March 2006 > sending email problem....
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
sending email problem....
|
|
| Tony Marquis 2006-03-31, 6:57 pm |
| Hi everyone,
The problem is really simple. When i try to send a message with this
function with a wrong sender email address, my script just stops...
as an exemple : sender address tony.iagdyu@feinc.com the error message
is - user not found on this server.... and the script stops.
-------------------------------------------------------------------------------------------------------------------------------------
use Mail::Sendmail;
use MIME::Lite;
use Email::Valid;
sub send_mail {
my ($mailto, $mailfrom, $sujet, $body_file, $file_send, $cc) = @_;
my $body_msg = "";
my $mail_err;
if ((Email::Valid->address( -address => $mailto, -mxcheck => 1 ) ?
'1' : '0') eq '0' ) {
($mailto, $mailerr, $mailrom) = ($mailfrom, $mailto,
"root\@feinc.com");
$sujet = "Destination invalide / Invalid destination $mailerr" .
$sujet;
if ((Email::Valid->address( -address => $mailto, -mxcheck => 1 )
? '1' : '0') eq '0' ) {
$sujet = "ERROR: $mailto $mailfrom " . $sujet;
$mailto = "tony\@feinc.com";
}
}
if ( $cc eq "1" ) {
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>$mailfrom,
To =>$mailto,
Cc =>$mailfrom,
Subject =>$sujet,
Type =>'multipart/mixed'
);
}
else {
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>$mailfrom,
To =>$mailto,
Subject =>$sujet,
Type =>'multipart/mixed'
);
}
open (FIC, $body_file) or die("Le fichier body $body n'existe pas\n");
while (<FIC> ) {
$body_msg .= $_;
}
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type =>'TEXT',
Data =>$body_msg
);
$msg->attach(Type =>'application/pdf',
Path =>$file_send,
Filename =>$file_name,
Disposition => 'attachment'
);
### Send in the "best" way (the default is to use "sendmail"):
MIME::Lite->send('smtp', "mail.xxxxxxxx.com", Timeout=>60);
$msg->send;
}
| |
| JupiterHost.Net 2006-03-31, 6:57 pm |
|
Tony Marquis wrote:
> Hi everyone,
> The problem is really simple. When i try to send a message with this
> function with a wrong sender email address, my script just stops...
>
> as an exemple : sender address tony.iagdyu@feinc.com the error message
> is - user not found on this server.... and the script stops.
While the script is a good thing to include, please resend with:
use strict;
use warnings;
and the code simplified to just the part that returns that error,
I say that because its just a sub{}, there is no call to it with example
data or the actual error (which would be helpfull to see where its
coming from, especially if you are reporting the error
croak "Email::Valid->address() said: $!"
if !Email::Valid->address->(...);
Now you'd know *exatly* where its coming from :)
|
|
|
|
|