How to mail in command line.

Hi
Can any one guide me how to mail in ssh command terminal with help of mutt or sendmail command from a proxy client machine . My proxy server is using squid proxy.

Most flavours of Unix have a mail or mailx command which you can use like this:

mail -s "a subject" recipient@example.com << HERE
some email body
HERE

If mutt is available, that offers a richer set of options, and the ability to sensibly include attachments to the message, with basically the same syntax.

Sendmail works the same way, too, but you need to put the headers in the message yourself.

sendmail -oi -t <<HERE
From: user@example.net
To: recipient@example.com
Subject: AYBABTU

All your base are belong to us
HERE

This is a FAQ; if you need more help, please search this site for threads related to your problem.

you have some ways to send files with mail/mailx

You can try like:

mail user@domain.com -c cc_user@domain.dom -s "Subject line" < filename

i was talking about

(echo "Body of e mail"; uuencode <list of files> ) | mailx -s "Subject of email" mail@addres

uuencode only accepts one file at a time, so you may need multiple uuencode commands or a for loop. The first optional parameter is the name of the local file, and the second paramater is the name given to the attachment. They are both assumed to be the same if only one parameter is given.

And UUENCODE is a legacy format anyway, you really want to use MIME attachments in this day and age.

uuencode is very convenient though... is there an equally convenient way to add MIME attachments? I know you can do the encoding with openssl enc -e -base64, for example, but then you have to generate the MIME headers and so-forth, right?

The FAQ has a script for properly formatting MIME attachments. The metamail package has a set of tools for base64 encoding and decoding as well as a slew of other MIME utilities (many of which are not very useful or convenient in the modern world, I have to add). The headers are not immensely complex or anything, but you do have to know a little bit about what you are doing if you construct a MIME structure by hand. The Perl MIME::Lite library is a nice front end for this, if you're into Perl.

Thanks for pointing those out. Not so complicated as you say... but I think I'll stick with uuencode since it's fairly ubiquitous.

Thank to all
I have tried with mail / mailx /sendmail / mutt command for mailing from command terminal, but it didn't worked . Is there any configuration or setting need for the client proxy host to send mail.

Which MTA (mail transmission agent?) are you running... is it sendmail? If so, does mailq list a bunch of emails which are queued to be delivered?

What operating system are you using exactly? The way to correctly configure your email gateway differs from one operating system to another, and between Linux distributions.

Does "it didn't worked" mean you got command not found or that it looked like it sent a message, but you never received it? You really need to be a bit more specific.

(Annihilannic: it's Mail Transport Agent fwiw.)

What operating system are you using exactly? - " Fedora 8 "

I'm using mutt for sending a mail with attachment. It doesn't gave any error and also the message is not yet recieved.

" mutt -s "hi subject" mail_id@sample.com -a sample.pdf < message_mail.txt "

the message_mail.txt contain the boby of the mail

If you telnet localhost 25 do you get a greeting banner identifying your MTA? (Type quit and press enter to terminate.)

Does mailq -v print anything?

hi
This is message i got when i tried with the telnet
[root@home ~]# telnet localhost 25
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
[root@home ~]#

You forgot to answer this one.

hi era

I apologize for my poor response.

Here is the message which i got in with mailq -v
/var/spool/mqueue (13 requests)
-----Q-ID----- --Size-- -Priority- ---Q-Time--- --------Sender/Recipient--------
m7C3q2oI020832 2789 1022684 Aug 12 09:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7BNq2oI020408 2841 1382874 Aug 12 05:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7BMvjoH020313 883 1471464+Aug 12 04:28 <root@fedoratest>
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7B3q2pp017778 2789 3182684 Aug 11 09:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7ANq2pp017354 3489 3543522 Aug 11 05:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7AMvjpo017259 883 3631464+Aug 11 04:28 <root@fedoratest>
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7A8q2pn015286 2436 4892476 Aug 10 14:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m7A3q2pn014756 2957 5342852 Aug 10 09:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m79Mvkpm008828 1051 5791632+Aug 10 04:28 <root@fedoratest>
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m793q2Aw006186 3710 7503608 Aug 9 09:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m78MvkAv005667 1809 7952389+Aug 9 04:28 <root@fedoratest>
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m78Cq25l004093 3637 8853542 Aug 8 18:22 MAILER-DAEMON
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
m788OZ5k003617 1944 9302316+Aug 8 13:54 <root@fedoratest>
(host map: lookup (fedoratest): deferred)
<root@fedoratest>
Total requests: 13

It can't find a host named fedoratest and so can't deliver to it.

Can you resolve it from the command line? Look into /etc/resolv.conf and related stuff. If it's a local, static host, maybe you just want to put its IP address in /etc/hosts