Monday, December 04, 2006

send attachments via mail app under console

If your mail server support 8-bit mode, you can directly use such commands:

    cat <attachment-file> | mail -s <subject> <email-address>

However lots of mail servers donot support 8-bit mode, so you'd better use the uuencode command. Firstly, prepare your mail, for example, named mymail, then,

    uuencode <attachment-file> <attachment-file> >> /tmp/mymail
Or
   cat <attachment-file> | uuencode <attachment-file> >> /tmp/mymail

Then, edit /tmp/mymail, and add your mail content before the attachment. After complete it, send it.

    cat /tmp/mymail | mail -s <subject> <mail-address>

Or directly:

    uuencode <attachment-file> <attachment-file> | mail -s <subject> <mail-address>

When received this mail, copy the content which belongs to mymail and save it into themail.uue. If the receiver reads it under MS Windows, he can unzip it with winzip 7.0 and acquire the attachment. If he under Linux, just use uudecode to restore the attachment:

    uudecode -o <attachment-file> themail.uue

If several files need to be dealed, i suggest you zip them into one package, and the attachment filename just is this package's filename.

There are some other ways, using mutt command:

    mutt -s "title" -a /dir/file1 mail@address

This command will call your editor to edit the mail content, thus you can firstly prepare your content, such as mailcontent.txt, to avoid to call the editor:

    cat mailcontent.txt | mutt -s "title" -a attachfile1 mail@address

No comments: