smtp-question

merlin's picture

They have: 410 posts

Joined: Oct 1999

i have an smtp-host as mailserver. now: how do i send mails over it?
what i have:

open(MAIL,"address of smtp-host";
print MAIL "To: $list{'tomail'}\n";
print MAIL "From: $list{'frommail'}\n";
print MAIL "Mailbody\n";
close(MAIL);
'

but somehow i don't get the mails... i'm not sure now, if this code is only for sendmail? if so, what's the syntax for smtp?
thanx for any help!

They have: 850 posts

Joined: Jul 1999

This is the code that I use, and it works fine:

#!/usr/local/bin/perl
$mail_prog = '/usr/lib/sendmail' ;
open (MAIL, "|$mail_prog -t");
print MAIL "To: $theiremail\n";
print MAIL "Reply-to: $youremail\n";
print MAIL "From: $youremail\n";
print MAIL "Subject: $subject\n";
print MAIL "$body\n";
close (MAIL);
'

merlin's picture

They have: 410 posts

Joined: Oct 1999

yes, but isn't this only for sendmail? i have smtp.mydomain.com instead of /usr/lib/sendmail ...?

They have: 161 posts

Joined: Dec 1999

There are Perl modules to help you do the job. I'd look at Mail::Mailer if I were you.

By the way, when sending email content (like, to sendmail), there has to be a blank line between the headers and the body of the message.

open MAIL, "| /usr/lib/sendmail -t" or
  die "can't open sendmail: $!";
print MAIL << "EOM";
To: $to
From: $from
Subject: $subject

Body of message
EOM
close MAIL or
  die "can't send mail: $!";
'

They have: 122 posts

Joined: Jun 2000

Yes, you have a SMTP host, but you do not understand Perl's open() function. Unless you open a pipe or are printing to some special device, you cannot simply open() a hostname. To connect to your SMTP host, you'd need to open up a socket to it, unless your SMTP host is the localhost, in which case you'd probably need to open a pipe to sendmail, as Rob P. and japhy showed. Doing open(MAIL, "smtp.domain.com") simply opens a file named 'smtp.domain.com', not a connection to that hostname.

Rob Radez
OSInvestor.com

merlin's picture

They have: 410 posts

Joined: Oct 1999

i see...
well, i looked in my cookbook for mail::mailer, and now it seems i understood what's going on... probably i'll be back again with more mail-questions, i don't hope so... Wink

merlin's picture

They have: 410 posts

Joined: Oct 1999

well, it's not running yet...
what i have now:

%headers = ({ From => $list{'frommail'},
To   => $list{'to'},
Subject => 'Subject' });

eval {
   use Mail::Mailer;
   $mailer = new Mail::Mailer 'smtp', 'SMTP.MYSMTP.COM';
   $mailer->open(\%headers);
     print $mailer $mailbody;
   $mailer->close;
};

if ($@) {
   print "could not send mail: $@";
} else {
   print "mail sent";
}
'
i always get an error:
could not send mail: No mailer type specified (and no default available), thus can not find executable program. at [scriptpath] line 102
'

it has something to do with the smtp-function i suppose? but what's wrong with it? the syntax i got from perldoc

They have: 1,587 posts

Joined: Mar 1999

is smtp access what u need to run a web based email site?

They have: 122 posts

Joined: Jun 2000

Web-based e-mail is usually either run locally or through IMAP.

On Mail::Mailer, try to find an example of how to use it. I think your precedence is screwed up when you try to make a new Mail::Mailer object.

Rob Radez
OSInvestor.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.