RE: Connecting to a socket

2010-03-31 Thread walt
Hi Rene,

You are absolutely right.  I don't intend to re-invent the wheel.  This is a
learning curve for me.  I would like to understand the ins and outs of smtp
better.  I have used net::smtp before and its great.  But I cannot figure
out how to get the module to return server messages so I can see whether the
email has been accepted or not. Turning on Debug works but there is too much
info.

I could do what I need with ASP's CDOSYS because that will report the error
from the smtp server, if any, but I'd like to get away from ASP as its
fairly limited unless you move up to .NET which is far too bloated for my
needs.  I like perl and CGI but I don't know enough yet to do this job.
I'll check out your suggestions, especially the sockets, and we'll see.

Anyway, thanks again for all you help.  Appreciate it,  Walter

-Original Message-
From: Rene Schickbauer [mailto:rene.schickba...@gmail.com] 
Sent: 31 March 2010 18:46
To: walt; Perl Beginners
Subject: Re: Connecting to a socket

walt wrote:
> Thanks Rene,
> 
> I already have an SMTP server running and have been using it with ASP and
> CDOSYS. Works like a charm but it's a bit cumbersome and restrictive.  So
I
> am looking into dynamically generating emails from a database to achieve a
> more personalized presentation.  At the same time I am hoping to use the
> server responses to identify and mark email addresses which are rejected
by
> the server(s) listed in the mx record. That way I'll cut down on the NDRs,
> at least that's the theory, and I hope I can iron out some of the problems
> this causes in maintaining the opt-in lists.

For my part, i just use Mail::Sendmail. Hasn't let me down so far. Of 
course, your mileage will vary, depending on your exact needs and mail 
volume.

> Then I was hoping to connect to the smtp server, issue the commands one by
> one and monitor the server response. My problem is I have never done that
so
> it's a bit of struggle understanding how to get perl to pick up the
server's
> response and react accordingly.

If you're planning to use this in a production environment, completly 
re-implementing a mailer might be the wrong choice.

For one thing, there are a ton of buggy mail systems out there. And if 
you're planning to send out anything more sophisticated than plain text 
mails without attachments, you'll have to worry about encondigs, 
Mime-types, delimiters, headers, the lot.

Not to mention handling temporary server errors, where you probably have 
to implement spooling, sender notifications, the lot.

Before re-inventing the wheel, at least take a look into 
http://search.cpan.org

For your specific problem, at least the socket part, you might wanna 
take a look into Net::SMTP. It's still pretty lowlevel, but does some 
wrapping about the low-level socket calls. (of course, reading the RFC's 
mentioned would still be a good idea).

> I'll check out the documentation you have mentioned, look into using
> IO::socket and maybe I can ask further questions later on.
> 
> Many thanks Walter.

Your welcome!

P.S.: Please always reply to the list as well.

LG
Rene


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Connecting to a socket

2010-03-31 Thread Rene Schickbauer

walt wrote:

Thanks Rene,

I already have an SMTP server running and have been using it with ASP and
CDOSYS. Works like a charm but it's a bit cumbersome and restrictive.  So I
am looking into dynamically generating emails from a database to achieve a
more personalized presentation.  At the same time I am hoping to use the
server responses to identify and mark email addresses which are rejected by
the server(s) listed in the mx record. That way I'll cut down on the NDRs,
at least that's the theory, and I hope I can iron out some of the problems
this causes in maintaining the opt-in lists.


For my part, i just use Mail::Sendmail. Hasn't let me down so far. Of 
course, your mileage will vary, depending on your exact needs and mail 
volume.



Then I was hoping to connect to the smtp server, issue the commands one by
one and monitor the server response. My problem is I have never done that so
it's a bit of struggle understanding how to get perl to pick up the server's
response and react accordingly.


If you're planning to use this in a production environment, completly 
re-implementing a mailer might be the wrong choice.


For one thing, there are a ton of buggy mail systems out there. And if 
you're planning to send out anything more sophisticated than plain text 
mails without attachments, you'll have to worry about encondigs, 
Mime-types, delimiters, headers, the lot.


Not to mention handling temporary server errors, where you probably have 
to implement spooling, sender notifications, the lot.


Before re-inventing the wheel, at least take a look into 
http://search.cpan.org


For your specific problem, at least the socket part, you might wanna 
take a look into Net::SMTP. It's still pretty lowlevel, but does some 
wrapping about the low-level socket calls. (of course, reading the RFC's 
mentioned would still be a good idea).



I'll check out the documentation you have mentioned, look into using
IO::socket and maybe I can ask further questions later on.

Many thanks Walter.


Your welcome!

P.S.: Please always reply to the list as well.

LG
Rene

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Connecting to a socket

2010-03-31 Thread Bob McConnell
From: Rene Schickbauer

> walt wrote:
>> I am new to Perl and want to connect to an smtp server on port 25 and
then
>> send it the helo, mail from:, rcpt to:, data, commands but I would
also like
>> to evaluate the response from the smtp server.
>> 
>> Has anyone got a script or can point me in the right direction?
> 
> A simple example on how to work with sockets can be found here:
> 
> 
> (just google for: perl io::socket tutorial)
> 
> As for the protocol, Wikipedia has a good article on that, look 
> especially at the included example:
> 
>

> 
> You should really also have a look at the official documentation of
SMTP:
> 
> 
> And yes, i know RFC821 is deprecated, and there are newer, more 
> complicated, more feature-rich versions of the protocol available. But
i 
> have yet to find a server that doesn't understand the basics layed out

> in this specification.

I believe the current document is RFC2821. It mostly extends the
original protocol and tries to clarify some explanations. So 821 is
still a proper subset. I do think it is best to read 821 first. One
difference that does matter is that the CR+LF pair as line terminator is
now explicitly required by both 2821 and 2822. That was not clear in the
originals.

Bob McConnell

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Connecting to a socket

2010-03-31 Thread Rene Schickbauer

walt wrote:

Hi,

I am new to Perl and want to connect to an smtp server on port 25 and then
send it the helo, mail from:, rcpt to:, data, commands but I would also like
to evaluate the response from the smtp server.

Has anyone got a script or can point me in the right direction?


A simple example on how to work with sockets can be found here:


(just google for: perl io::socket tutorial)

As for the protocol, Wikipedia has a good article on that, look 
especially at the included example:




You should really also have a look at the official documentation of SMTP:


And yes, i know RFC821 is deprecated, and there are newer, more 
complicated, more feature-rich versions of the protocol available. But i 
have yet to find a server that doesn't understand the basics layed out 
in this specification.


BTW, re-implementing the client-side part of the SMTP protocol - while 
not very usefull because there are tested modules around -  is in my 
opinion a very good practice for beginners. The protocol's design is 
clean. The minimum requirements to get a working module are just that: 
minimal. And getting a test server up and running  is rather simple: 
Most Linux/Unix distros already run some SMTP server on localhost, so 
you can deliver mails to local users the moment to finished setting up 
your machine[1][2].


LG
Rene

[1] If it doesn't work by default, look in the docs of your OS. You 
probably only have to enable the sendmail service or something like that.


[2] Tested on Ubuntu 9.10:

ca...@plunger:~$ telnet localhost 25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 plunger ESMTP Exim 4.69 Wed, 31 Mar 2010 17:18:06 +0200
HELO localhost
250 plunger Hello localhost [127.0.0.1]
MAIL FROM: ca...@localhost
250 OK
RCPT TO: ca...@localhost
250 Accepted
DATA
354 Enter message, ending with "." on a line by itself
Subject: This is a test mail

Yada? Yadayadayada!
Foo? No Bar!!!
.
250 OK id=1Nwzgt-0006JL-0Y
quit
221 plunger closing connection
Connection closed by foreign host.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Connecting to a socket

2010-03-31 Thread walt
Thanks Deborah,

 

That's works fine on my local smtp relay server.  But.. how can I get the
script to check the server response after issuing  the 

$smtp->to $var ?  I want to trap any rejections by the server.

 

Meantime I'll see if I can find documents on Net::SMTP

 

Thanks again,  Walter

 

From: Deborah Martin [mailto:deborah.mar...@kognitio.com] 
Sent: 31 March 2010 14:47
To: 'walt'
Subject: RE: Connecting to a socket
Importance: High

 

Walter, 

You could adapt the following program :- 

#!/usr/bin/perl 
# Simple email program 
use Net::SMTP; 

my $from= 'yourf...@address'; 
my $site= 'yoursitename';  
my $smtp_host   = 'yourmailhost';  
my $to  = 'you...@address'; 

my $smtp= Net::SMTP->new($smtp_host, Hello => $site); 

$smtp->mail($from); 
$smtp->to($to); 
$smtp->data(); 

$smtp->datasend("To: $to\n"); 
$smtp->datasend("Subject: A message from a Perl program\n"); 
$smtp->datasend("\n"); 
$smtp->datasend("This is a test message from a Perl program\n"); 

$smtp->dataend(); 
$smtp->quit; 

Regards, 
Deborah 

-Original Message- 
From: walt [mailto:w...@helvatron.co.uk] 
Sent: 31 March 2010 14:39 
To: beginners@perl.org 
Subject: Connecting to a socket 

Hi, 

I am new to Perl and want to connect to an smtp server on port 25 and then
send it the helo, mail from:, rcpt to:, data, commands but I would also like
to evaluate the response from the smtp server.

Has anyone got a script or can point me in the right direction? 

I know I could use mailman or sendmail but I want to learn how to format
emails on the fly and evaluate the server response which I can't do using a
relay server.

Many thanks,  Walter 

 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional
commands, e-mail: beginners-h...@perl.org http://learn.perl.org/


***
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. 

Any unauthorised distribution or copying is strictly prohibited. 
Whilst Kognitio Limited takes steps to prevent the transmission of viruses
via e-mail, we can not guarantee that any email or attachment is free from
computer viruses and you are strongly advised to undertake your own
anti-virus precautions. 

Kognitio grants no warranties regarding performance, use or quality of any
e-mail or attachment and undertakes no liability for loss or damage,
howsoever caused. 

Kognitio Limited, a company registered in England and Wales. Registered
number 0212 7833. Registered Office: 3a Waterside Park, Cookham Road,
Bracknell, Berks, RG12 1RB. VAT number 864 4378 92.

Kognitio Inc, a company incorporated in Delaware, principal office 180 North
Stetson, Suite 3500, Chicago, IL 60601, USA
***



Re: Connecting to a socket

2010-03-31 Thread Jeff Peng
On Wed, Mar 31, 2010 at 9:39 PM, walt  wrote:
> Hi,
>
> I am new to Perl and want to connect to an smtp server on port 25 and then
> send it the helo, mail from:, rcpt to:, data, commands but I would also like
> to evaluate the response from the smtp server.
>
> Has anyone got a script or can point me in the right direction?
>


Hi,

Could you use Net::SMTP and enable the debug option to trace the process?


-- 
Jeff Peng
Email: jeffp...@netzero.net
Skype: compuperson

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/