Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

SMTP client.

by Punto (Scribe)
on Jun 26, 2000 at 09:17 UTC ( [id://19805]=perlquestion: print w/replies, xml ) Need Help??

Punto has asked for the wisdom of the Perl Monks concerning the following question:

Hi..

I need to sendn a mail from a perl script. I'm using MIME::Entity to create the e-mail, so I have a string like this to print out to sendmail:

To: somebody@domain.com
From: me@domain.com
etc

But I want to use the script on a system that doesn't have sendmail, or maybe use a different SMTP server, other than localhost. I need to use MIME::Entity because I'm sending attachments. What would be another way to send the e-mails? I say Mail::Sendmail and Net::SMTP, but they all have commands like this:

$mail = {To => 'somebody@domain.com', From => 'me@domain.com', etc
or something, but I alredy have all the mail on a string. Any ideas?

thanks..

Replies are listed 'Best First'.
Re: SMTP client.
by lhoward (Vicar) on Jun 26, 2000 at 16:33 UTC
    Using <cpan://Net::SMTP> will work fine. It is the nature of internet e-mail that you set the from and to twice if you do raw SMTP; once in the e-mail header and once in the SMTP session. There's a good O'Reilly book Programming Internet Email that goes into all the nasty details of this stuff.

    Here's an example from a piece of my code. In this case I uses MIME::Lite to do the actual encoding, but the process should be the same with MIME::Entity. I've removes the error checking in the Net::SMTP communication to make the code smaller and easier to post; you should add the error checking back if you plan to use Net::SMTP. One other note is that MIME::Lite has its own send method that will send the message. So unless you need (or want) to do the SMTP negotiation yourself, MIME::Lite may be an easier solution for you as it can encode, add attachments and send the message.

    use Net::SMTP; use MIME::Lite; my $from='foo@testdomain.com'; my $to='bar@testdomain.com' my $msg_html_rich = new MIME::Lite( From => $from, Subject => 'MIME::Lite Test', To => $to, Type => 'multipart/alternative'); attach $msg_html_rich Type =>'text/plain', Data =>'message in plain text'; attach $msg_html_rich Type =>'text/html', Data =>'message in <b>HTML</b> with <i>many</i> markup tags'; my $smtp= Net::SMTP->new('127.0.0.1', Timeout => 180); $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend($msg_html_rich->as_string); $smtp->dataend();
Re: SMTP client.
by httptech (Chaplain) on Jun 26, 2000 at 16:43 UTC
    If your system doesn't have sendmail, it's probably got some other MTA which could possibly emulate sendmail's "-t" option.

    If you are wanting to send mail to another SMTP server aside from localhost, you are going to have to talk the SMTP protocol in your script, or write a script to act like sendmail -t, and pass the message off to it.

    The best solution really depends on your situation; what platform are you dealing with, and what are your choices for sending mail locally? Sending through a remote SMTP server would be my last choice.

Re: SMTP client.
by ZZamboni (Curate) on Jun 26, 2000 at 19:20 UTC
    You could try looking at both Mail::Internet and Mail::Mailer. The latter allows sending mail using different methods, may be what you want. The former allows composing and manipulating mail messages, including parsing from a string, so you could parse your existing string to extract the corresponding headers. Although if you are building the message in the first place, you may already have them handy.

    --ZZamboni

Re: SMTP client.
by Anonymous Monk on Jun 27, 2000 at 22:52 UTC
    If you are running on an NT box you may wish to try the freeware SMTP client blat at http://gepasi.dbs.aber.ac.uk/softw/Blat.html. We use blat with Perl with excellent results. You must have mail relay privileges on the SMTP server.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://19805]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-23 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found