SMTP Question

Manning, Rob Rob_Manning at mail.ci.baltimore.md.us
Tue Dec 7 06:49:33 CST 1999


> -----Original Message-----
> From:	Christopher Shannon [SMTP:cshannon at mdo.net]
> Sent:	Friday, December 03, 1999 11:28 AM
> To:	Manning, Rob
> Subject:	SMTP Question
> 
> Rob,
> 
> Just before we get into the next meeting, I was just trying out one of
> your
> SMTP examples.  I have observed the following behaviour and have some
> questions.  First, here is my code:
> 
> use Custom::Spammer;
> 
> $mail_to='Chris <cshannon at mdo.net>';
> $mail_from='blah <blah at ghqd.org>';
> $mail_subj='This is another test';
> $mail_art='And this is the message';
> 
> Custom::Spammer::send_mail($mail_to, $mail_from, $mail_subj,
> $mail_art);
> 
> 
> -----------------------------------------------
> [This is from a custom module I've made.]
> 
> package Custom::Spammer;
> use strict;
> 
> sub send_mail {
>  my ($m_addr, $smtp);
>  my $addr=shift;
>  my $from=shift;
>  my $title=shift;
>  my $article=shift;
> 
>  require Net::SMTP;
> 
>  $m_addr=$addr;
>  $m_addr=~s/^(.*?@(.*?)>.*?)$/\2/;
>  $smtp=new Net::SMTP('mail.'.$m_addr);        # Refer to question 2
>  $smtp->mail($from);
>  $smtp->to($addr);
>  $smtp->data();
>  $smtp->datasend("To: $addr\n");
>  $smtp->datasend("From: $from\n");
>  $smtp->datasend("Subject: $title\n\n");
>  $smtp->datasend($article);
>  $smtp->dataend();
>  $smtp->quit;
> }
> 1;
> 
> 
> (1) When I send a test file, using the command line, I get the
> following
> message:
> 
>         "The system cannot find the path specified."
> 
> Since Net::SMTP uses Carp, it must be something from STDERR
> But nonetheless, my message gets to its destination.
> 
> Why does it do this, and is there any way to surpress output to
> STDERR? (Or
> is there something I should or should not do so I don't get this
> error.)
> Just so if I am using it
> in a CGI application, it does not generate one of those nasty screens
> no one
> likes to see.
> 
> (2) What if you don't precisely know the name of the SMTP server
> you're
> sending to?  For example,
> in the code above, I prepended 'mail.' to the base of the e-mail
> address.
> But what if the SMTP server
> does not follow this convention?  Or is it mandatory that they follow
> it?
> In otherwords, if there is a mail server at xyz.net, will it always be
> named
> mail.xyz.net?
> 
> (3) And finally, should I have posted this to the B'more Perl Mongers'
> address instead of you personally?
> 
> Regards, Chris Shannon
> 
> P.S.  You can add this to your list of examples: A script for posting
> to a
> usenet newsgroup (also a part of Custom::Spammer):
> 
> sub send_news {
>  my $news_server;
>  my $news_group=shift;
>  my $from=shift;
>  my $title=shift;
>  my $article=shift;
> 
>  # this script was tested with biz-direct.net,
>  # which is a free, public news server
>  # syntax:
>  # Custom::Spammer::send_news('biz-direct.net', 'alt.thisgroup',
> 'me at xyz.net',
>  # 'My_Subject', $my_article);
> 
>  require Net::NNTP;
>  my $server=new Net::NNTP($news_server) or die "Can't connect to news
> server: $@\n";
>  my ($articles, $strt, $lst, $group_name) =
> $server->group($news_group)
>      or die "Can't select $news_group\n";
> 
>  push (my @article, "Newsgroups: $news_group\n");
>  push (@article, "From: $from\n");
>  push (@article, "Subject: $title\n\n");
>  push (@article, $article);
>  my $retval=$server->post(@article) || die "Cannot post $!";
>  $server->quit;
> }
> 
Chris,
	I've been doing a little bit of research into why that
error message is generated.  I've always wondered where it
was coming from so now's my chance to find out!

Of course on Win/NT you can redirect STDERR to a file or nul (same as
/dev/null on UNIX).
This just hides the sympton, but may be useful in a script that produces
formatted output:

<command> 2> <file>   or
<command> 2> nul

In regard to your question about not knowing the mail server you
are sending mail to, remember Internet mail is a system that 
abstracts you from knowing HOW mail is delivered, so it's not
necessary for you to know the destination mail server.  The only
mail server address you need to be concerned with giving to 
the SMTP object constructor (new) is the ip address or hostname of your 
outgoing mail relay host.  This should be the same as what you
specify in your mail client (i.e. Eudora, Netscape Messenger,
MS Outlook/Exchange etc.) for the "outgoing mail host" or 
something to that effect in the mail server properties configuration
section of your client.  As usual contact your network administrator 
if your not sure which machine is the outgoing mail server for your
network.
(Sometimes it is the same as the machine you collect your mail from 
using POP3, BUT NOT ALWAYS!).  It be nice if all sites adopted
a standard naming scheme for their servers like smtp.sub-domain.com, 
but it is very much up to the discretion of the Network Administrator.

I always encourage folks to use the mailing list to pose
questions/observations to 
the group, especially when they're related to Perl :-) 

Rob

Rob Manning                                     manningr at tcsnet.net
Senior Systems Analyst                      Work (410) 396-4963
TeleCommunication Systems               Fax  (410) 837-0546
--
Looking for a  Perl user's group in Baltimore? - http://baltimore.pm.org




More information about the Baltimore-pm mailing list