Solved

how to use IO::Socket

Posted on 2002-03-16
5
431 Views
Last Modified: 2008-03-17
Maneshr...to answer your question.

Yes, I do know the smtp and pop3 server names to test out the IO::Socket module.  I will also be running my own mail server from IIS in Win2k server in the near future.

Is it safe to be opening up new sockets on the fly?  Maybe that was a dumb question.
0
Comment
Question by:GorGor1
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 6872903
GorGor1,

".. I will also be running  my own mail server from IIS in Win2k server in the near future...."

Excellent!!

Try this script that i have been using for a long time now.

It works just fine for me.

Let me know how it works on your server.

===gorgor.pl
$|++;

&sendMail('mail.server.com','from_your_email_id@server.com','recipeient@server.com','Testing',"Testing 1-2-3\nRgds,\n");

sub sendMail {
     my ($host, $from, $to, $subject, $message) = @_;

     require IO::Socket;
     my $remote = IO::Socket::INET->new(
     Proto    => "tcp",
     PeerAddr => $host,
     PeerPort => "smtp(25)",
     ) || die $!;
     my $debug = <$remote>;
     print $remote "MAIL FROM: $from\n";
     $debug .= <$remote>;
     print $remote "RCPT TO: $to\n";
     $debug .= <$remote>;
     print $remote "DATA\n";
     $debug .= <$remote>;
     print $remote "From: $from\nTo: $to\nSubject: $subject\n\n";
     print $remote "$message\n";
     print $remote ".\n";
     $debug .= <$remote>;
     close $remote;
     return $debug;
 }
0
 
LVL 1

Author Comment

by:GorGor1
ID: 6872943
BLAM!  It worked like a freakin charm!  Is there an easy way to format the message of the e-mail or do I pretty much have to use the '\n' and '\t' stuff for formatting?

Also, is it capable of attachments?

And finally, does it close the PeerPort after it's finished?

Thanks!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6872961
GorGor1,

"..BLAM!  It worked like a freakin charm! .."

Super!!! I would have been surprised with anything less that that :-)

"..Is there an easy way to format the message of the e-mail or  do I pretty much have to use the '\n' and '\t' stuff for formatting?..."

Yes. There is an easy way to format it.

You can use the following approach...

$message=qq{
Here is the first line

Here is the 2nd line?

Thanks!!!

Rgds,

GorGor1
};

&sendMail('mail.server.com','from_your_email_id@server.com','recipeient@server.com','Testing',$message);

"..Also, is it capable of attachments?.."

Right off the bat, my answer would be yes. However, i have not yet extended this script to do that. Therefore, i cannot post any sample code here :-(

"..And finally, does it close the PeerPort after it's finished?.."
Yes. The Socket port is closed with the following statement.

close $remote;

Hope that helps.
0
 
LVL 1

Author Comment

by:GorGor1
ID: 6873012
U da man!  Once again, you've saved me a ton of headache.  I'll post again someday when I need to do an attachment and I'll see if you've come up with anything yet.  Thanks again!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 6873018
GorGor1,

"..U da man!  Once again, you've saved me a ton of headache..."

Thank you!!!

Glad to know i could be of help to you.

"..  I'll post again someday when I need to do  an attachment and I'll see if you've come up with anything yet. .."

Hopefully by then i should have the attachement piece added, tested and working fine.

Till then........................
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pattern matching in perl 2 101
Union rows in array that have common elements 2 89
Regular Expression for URL 10 91
what are these modules in perl script 4 94
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now