Email external address thru Perl script

Email external address thru Perl script

Post by Darr » Wed, 22 Jan 2003 03:35:53



Hello all. I'm having an issue trying to email from Perl. I'm running
Mandrake 8.1 and want to send email from within a Perl script to an
external address (outside of my box). Whenever I try I don't get the
email and I get a bounce in my local email saying that I was sending
to an "unknown user". For example, If I try and send to


'myexternal.net'".

It seems that it is looking for any address only on my box. How can I
get it to look at the internet to deliver mail thru Perl? For the
record, I wrote a script to send email from PHP and it works fine.
Also, sending mail from the command line like this:


Works fine as well. I know I can use the back ticks to sort of "fudge"
it to work but I don't have shell access on my web provider space, so
it may work here but won't work there (which is ultimately where I'd
use this). This is the code I use:

#!/usr/bin/perl

$mailprog = "/usr/lib/sendmail";



$name = "Darryl";
$subject = "This is a test";
$body = "This is my perl emailer test";

open(MAIL,"|$mailprog -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL $body;
close(MAIL);

Any ideas?

Darryl

 
 
 

Email external address thru Perl script

Post by ynotsso » Wed, 22 Jan 2003 04:46:47



> Hello all. I'm having an issue trying to email from Perl. I'm running
> Mandrake 8.1 and want to send email from within a Perl script to an
> external address (outside of my box). Whenever I try I don't get the
> email and I get a bounce in my local email saying that I was sending
> to an "unknown user". For example, If I try and send to


> 'myexternal.net'".

[...]

Would you post all the relevant entries from a single instance in the
sendmail log, please; usually /var/log/maillog.

There is a unique message ID associated with each transaction, so grep for
that message ID to get everything.

      tony

--
use hotmail.com for any email replies

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 
 
 

Email external address thru Perl script

Post by Michael Heimin » Wed, 22 Jan 2003 05:54:02




> Works fine as well. I know I can use the back ticks to sort of "fudge"
> it to work but I don't have shell access on my web provider space, so
> it may work here but won't work there (which is ultimately where I'd
> use this). This is the code I use:
> #!/usr/bin/perl

make that #!/usr/bin/perl -w

Quote:> $mailprog = "/usr/lib/sendmail";

Sure?



> $name = "Darryl";
> $subject = "This is a test";
> $body = "This is my perl emailer test";
> open(MAIL,"|$mailprog -t");
> print MAIL "To: $to\n";
> print MAIL "From: $from\n";
> print MAIL "Subject: $subject\n\n";
> print MAIL $body;
> close(MAIL);
> Any ideas?

Should work, the only problem I could imagine, from your post,
the path to sendmail is wrong or/and you are trying to fake
the From: and sendmail doesn't trust you.

Michael Heiming
--
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of SPAM

 
 
 

Email external address thru Perl script

Post by Darr » Thu, 23 Jan 2003 03:21:28



> > Hello all. I'm having an issue trying to email from Perl. I'm running
> > Mandrake 8.1 and want to send email from within a Perl script to an
> > external address (outside of my box)


> Would you post all the relevant entries from a single instance in the
> sendmail log, please; usually /var/log/maillog.

Here's a log...

Jan 21 01:06:53 mybox postfix/pickup[22369]: 3F6AE58587: uid=502
from=<linuxuser>
Jan 21 01:06:53 mybox postfix/cleanup[22375]: 3F6AE58587:

Jan 21 01:06:53 mybox postfix/qmgr[2120]: 3F6AE58587:

size=371, nrcpt=1 (queue active)
Jan 21 01:06:53 mybox postfix/local[22377]: 3F6AE58587:

relay=local, delay=0, status=bounced (unknown user: "myexternal.net")
Jan 21 01:06:53 mybox postfix/cleanup[22375]: 8909358586:

Jan 21 01:06:53 mybox postfix/qmgr[2120]: 8909358586: from=<>,
size=1974, nrcpt=1 (queue
active)
Jan 21 01:06:53 mybox postfix/local[22377]: 8909358586:

relay=local, delay=0, status=sent ("|/usr/bin/procmail -Y -a $DOMAIN")

The names have been changed to protect the innocent. Note that the

which shows up nowhere in the log. It gets changed to

again to make sure I got all of the log info on sending the email,
which is what I just posted. Any ideas?

Darryl, still stumped

P.S. Of course sending mail from the command line still works fine...

 
 
 

Email external address thru Perl script

Post by Martin Blum » Thu, 23 Jan 2003 04:42:43




> Hello all. I'm having an issue trying to email from Perl. I'm running
> Mandrake 8.1 and want to send email from within a Perl script to an
> external address (outside of my box). Whenever I try I don't get the
> email and I get a bounce in my local email saying that I was sending
> to an "unknown user". For example, If I try and send to


> 'myexternal.net'".

Haven't much knowledge about Perl, I have to admit to my shame. But perhaps

silently, and what rests is myexternal.net, which sendmail then interprets

Does your code work with a local user as recipient?
Instead of sending it off to sendmail, send it to another script that just
logs it in a file.

Just a wild guess.
HTH
Martin

 
 
 

Email external address thru Perl script

Post by jack » Thu, 23 Jan 2003 19:34:53



> #!/usr/bin/perl

> $mailprog = "/usr/lib/sendmail";



> $name = "Darryl";
> $subject = "This is a test";
> $body = "This is my perl emailer test";

> open(MAIL,"|$mailprog -t");

Just a thought (after other posted here already): Why not try to
avoid the "-t" option here...?

 From what You describe, the problem seems to be somewhere in how
sendmail tries to extract the recipient address from the body.

Quote:> print MAIL "To: $to\n";
> print MAIL "From: $from\n";
> print MAIL "Subject: $subject\n\n";
> print MAIL $body;
> close(MAIL);

> Any ideas?

> Darryl

Give it a try.

Cheers, Jack.

--
----------------------------------------------------------------------
My personal reading of the string "MicroSoft" expands to "NanoWeak"...

 
 
 

Email external address thru Perl script

Post by Lior Marantenbo » Thu, 23 Jan 2003 22:04:39


Try maybe this line:


instead of

Maybe that could help.


> Hello all. I'm having an issue trying to email from Perl. I'm running
> Mandrake 8.1 and want to send email from within a Perl script to an
> external address (outside of my box). Whenever I try I don't get the
> email and I get a bounce in my local email saying that I was sending
> to an "unknown user". For example, If I try and send to


> 'myexternal.net'".

> It seems that it is looking for any address only on my box. How can I
> get it to look at the internet to deliver mail thru Perl? For the
> record, I wrote a script to send email from PHP and it works fine.
> Also, sending mail from the command line like this:


> Works fine as well. I know I can use the back ticks to sort of "fudge"
> it to work but I don't have shell access on my web provider space, so
> it may work here but won't work there (which is ultimately where I'd
> use this). This is the code I use:

> #!/usr/bin/perl

> $mailprog = "/usr/lib/sendmail";



> $name = "Darryl";
> $subject = "This is a test";
> $body = "This is my perl emailer test";

> open(MAIL,"|$mailprog -t");
> print MAIL "To: $to\n";
> print MAIL "From: $from\n";
> print MAIL "Subject: $subject\n\n";
> print MAIL $body;
> close(MAIL);

> Any ideas?

> Darryl

 
 
 

Email external address thru Perl script

Post by Darr » Fri, 24 Jan 2003 01:23:45



> Just a thought (after other posted here already): Why not try to
> avoid the "-t" option here...?

Tried it, same result. Thanks for the suggestion though.

Quote:>  From what You describe, the problem seems to be somewhere in how
> sendmail tries to extract the recipient address from the body.

Yeah. I'm just not sure why it's trying to do any interpreting at all.
It almost seems like there's a "local" switch somewhere that's turned
on and it's assuming all mail sent from Perl is local. Or somehow Perl
is mangling the address before it gets to sendmail. Personally, I'm
stumped.

Darryl

 
 
 

Email external address thru Perl script

Post by Darr » Fri, 24 Jan 2003 01:38:36





> > Works fine as well. I know I can use the back ticks to sort of "fudge"
> > it to work but I don't have shell access on my web provider space, so
> > it may work here but won't work there (which is ultimately where I'd
> > use this). This is the code I use:

> > #!/usr/bin/perl

> make that #!/usr/bin/perl -w

> > $mailprog = "/usr/lib/sendmail";

> Sure?

Positive...sort of. That is the location of the "sendmail wrapper". My
system is actually using Postfix for the mailing, but the link is in
that location so stuff that expects sendmail will work.

Quote:

> > Any ideas?

> Should work, the only problem I could imagine, from your post,
> the path to sendmail is wrong or/and you are trying to fake
> the From: and sendmail doesn't trust you.

I tried changing my "From" to the same as my local user and it does
the same thing (running the Perl script from the command line as that
user).

One thing that I just noticed is that if I send the email locally it
works, but if I use a non-local "From" address it changes that as

my local user on my box, I get the email, but the "From" field says

BE local whenever I send something from Perl, and it changes the
"From" and "To" lines before sending.

Darryl

 
 
 

Email external address thru Perl script

Post by Darr » Fri, 24 Jan 2003 09:03:31



> Try maybe this line:


> instead of

> Maybe that could help.

Here I am trying to check configuration files and looking up How To's
on my operating system  and the problem was I quoted the string wrong.

Actually this works:


I continually forget that double quotes interpets everything in the
string! Anyway thanks for the suggestion! Of course I figured it out
about 3 seconds after you posted this. Thanks again!

Darryl