Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a server in my flat running Gentoo. I would like to set up a mail server which will just send an emali out to my external email address (eg hamish@hotmail) with some system information, eg my disk quota.
Therefore, I would like a mail server which just send out mail, doesn't receive any mail and doesn't store any mail. Basically, I need a simple system and a fairly simple way to set it up.
I have read about sendmail, and i guess that application would do this, however, I have heard that it is a pain in the ass to configure.
I have also been reading a bit about Exim mail server which is supposedly one of the easiest to configure.
Do i need anything sophisticated to set this up, or will something simple suffice?
I think you might have to install Net::SMTP library as well. But the good news is that those libraries don't need any configuring.
Also, that script I posted does not have a 'shebang' line on it, and you'll need to know how to get your message into the perl variable.
I'll tell you what. Because I am in a good mood, I'll work on it tonight, and outline the steps (I can't do this now because I'm on a Windows box now ).
Last edited by jlangelier; 12-09-2004 at 03:53 PM.
One question. This will easy if your machine has access to an outgoing mail server (for example, your ISP's mail server).
So do your machine have access to an outgoing mail server?
If you can use an email program (i.e. KMail or Pine, or whatever) to send email from your machine, that (obviously) means you have access to an outgoing mail server.
Otherwise, it'll be hard (i.e. if all you have is hotmail).
OK, you inspired me to go and write my own scripts which run daily and mail stats to myself. Way cool.
Problem is, you must have access to an SMTP server. Chances are your ISP has an SMTP server. If not, let me know, and we'll share a sob and go to plan 'B' (which will likely be to find you an SMTP server )
I had planned on using the Mail::Mailer module (Perl speak for 'library'). But Mail::Mailer requires Net::SMTP, so I cut out the middleman and just used Net::SMTP.
Chances are good you already have Net::SMTP. You can verify that by doing a locate on SMTP.pm
Or, run the script. If you don't have Net::SMTP, Perl will tell you.
If you don't have Net::SMTP let me know and I'll tell you how to install it. But you probably have it (I had it in my default install, but then again, I run slackware ) You'd have to go to cpan.org, search for Net::SMTP, download the tar.gzip, unzip it, and read the README. But hopefully you've got it already.
Here's the script:
Code:
#!/usr/bin/perl
# simplemail 1.0
# Released to the public domain. No copyright.
# Hacked together in about a half hour by JLangelier (and it shows)
use Net::SMTP;
use Getopt::Std;
sub Usage;
getopts('t:f:m:s:j:d');
if ($opt_d) {
$debug = 1;
} else {
$debug = 0;
}
if ($opt_t) {
$toAddress = $opt_t;
} else {
Usage;
}
if ($opt_f) {
$fromAddress = $opt_f;
} else {
Usage;
}
if ($opt_m) {
$pathToMessage = $opt_m;
} else {
Usage;
}
if ($opt_s) {
$SMTPServer = $opt_s;
} else {
Usage;
}
if ($opt_j) {
$subject = $opt_j;
} else {
Usage;
}
open (INPUT, "$pathToMessage") or die "Could not open $pathToMessage for reading\n";
while ($line = <INPUT>) {
$message .= $line;
}
close INPUT;
if ($debug) {
$smtp = Net::SMTP->new($SMTPServer, Debug => 1);
} else {
$smtp = Net::SMTP->new($SMTPServer);
}
die "Couldn't connect to server" unless $smtp;
$smtp->mail( $fromAddress );
$smtp->to( $toAddress );
$smtp->data();
$smtp->datasend("To: $toAddress\n");
$smtp->datasend("From: $fromAddress\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$message\n");
$smtp->dataend();
$smtp->quit();
exit 0;
sub Usage {
print "\nArguments (all required)\n";
print "\t-t = to address\n";
print "\t-f = from address\n";
print "\t-m = path to message\n";
print "\t-s = SMTP server\n";
print "\t-j = Subject\n\n";
print "Options\n";
print "\t-d = Print SMTP debugging messages\n\n";
print "Sample Invocation:\n";
print "\tsimplemail -m message.txt -s some.stmphost.com -t foo@example.net -f bar@test.com -j 'Test Subject'\n";
exit 1;
}
Here's how you run it. Save it as 'simplemailer' wherever you save your usr scripts (I put mine in /usr/local/scripts) . At the top of the script, the first line has a path to Perl. Make sure your Perl is there (do a 'which perl' to verify). Edit the line to point to your Perl. Make the script executable.
The script expects a path to a text file which it will send. This text file is where you would put your statisticts. Write a text file you wish to send. Execute the script to get the usage and a sample invocation.
I set up a daily cron job to run another script, which generates a text file showing disk free space, 'top' output, and a fortune for grins. Then that other script dials up (I don't have broadband) if a dialup connection is not active, and invokes the 'simplemail' script as outlined above. I assumed you knew how you were going to grab your stats and were planning to put it in a text file for sending, but if not, give a holler.
I have probably assumed some knowledge in the above that you or others may not have, so don't hesitate to ask. I hope it works. It works for me, but YMMV.
And this example, my friends, shows why Perl is called 'The Duct Tape of the Internet'. Learn it. Love it. Use it.
Oh yeah, if the email doesn't go out, use the -d switch to see the debug messages from the SMTP module.
Last edited by jlangelier; 12-09-2004 at 10:22 PM.
Most modules are object oriented. At that point in the code, $smtp is a Net::SMTP object. The -> calls the 'mail' method. If you don't know object oriented programming, that's not going to make alot of sense.
The good news is that you can write perl without knowing object oriented programming. Just follow the examples for the modules, and that can be the only time you need to do object oriented stuff.
Quote:
In the line $smtp->data(); is the "data()" a built-in smtp command, or is it specified above?
Again, that is a call to the 'data' method for the Net::SMTP object. Because it has no arguments, I'm assuming it initializes the object (I just copied that code from the module documentation which is why I'm not sure).
Quote:
What does INPUT mean in this context?
INPUT, in that context, is a file handle. I opened a file and gave it the handle 'INPUT' (I could have called it FOOBAR for that matter) and from then on I can refer to that file using the handle: INPUT.
Quote:
Thanks so much for your help, you have inspired me to learn perl!!!
The great thing about Perl is that you can begin writing it very quickly, just using Perl 'baby talk'. Think of Perl as kind of a high-powered shell scripting language. The really excellent part about it is that there are thousands of different modules, which can do pretty much anything you need with ease.
Last edited by jlangelier; 12-10-2004 at 10:55 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.