Advertisement

Email from command line (Unix)

Started by June 15, 2001 04:52 PM
2 comments, last by NuffSaid 23 years, 7 months ago
I need to send an email from the command line. Could anybody please help me? The problem I''m having is that I''ve got my assignments on the uni''s Unix server and the printer connected to it is DOWN. Thus, the only way I can print my assignments is to send a copy of the file to my email address and print them from home. And no, there isn''t a floppy drive or other form of removal media on the stupid machine, so I''ll have to use email. There isn''t a GUI either, that''s why it must be command line. Could anybody help? Please...... If it is important, the version of Unix is Solaris 5
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Does the server have Pine on it? If so, use it.

If not, use the mail command. Type ''man mail'' for all the details.

~~~~~~~~~~
Martee
http://www.csc.uvic.ca/~mdill
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
Easy peasy.

If the server has sendmail on it (very likely) then open up "/usr/sbin/sendmail -t" (or wherever it is, you can find it out by typing "whereis sendmail") and then pipe your email & headers to the standard input. Heres a quick perl script that you can just copy and paste and modify as appropriate:

    #!/usr/bin/perl -wmy $sendmail = "/usr/sbin/sendmail";my $to_address = 'whatever@company.com';my $from_address = 'whatever@company.com';my $subject = "Look, heres that assignment i wanted";open(MAIL, "|$sendmail -t") || die "Could not open $sendmail : $!\n";print MAIL <<"ENDMAIL";To: $to_addressFrom: $from_addressSubject: $subjectMy Email Message here!ENDMAILclose(MAIL);  


or, if you want to be clever and open up your assignment file and then print it to the email...

       #!/usr/bin/perl -wmy $sendmail = "/usr/sbin/sendmail";my $to_address = 'whatever@company.com';my $from_address = 'whatever@company.com';my $subject = "Look, heres that assignment i wanted";my $file = "/home/wherever/your/file/is";open(MAIL, "|$sendmail -t") || die "Could not open $sendmail : $!\n";print MAIL <<"ENDMAIL";To: $to_addressFrom: $from_addressSubject: $subjectENDMAILopen(FILE, "$file") || die "Could not open $file  : $!\n";my @contents = <FILE>;close(FILE);print MAIL @contents;close(MAIL);  


Thinking about it im not to sure if the second example will work with old perl versions, but its worth a shot.

Edited by - jumble on June 16, 2001 5:06:30 AM
jumble-----------
Thanks guys. I''ve managed to get mail to work.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.

This topic is closed to new replies.

Advertisement