SUSE & openSUSE

Tips,Tricks, Tutorials,How Tos and Troubleshooting suse linux

How to send email with attachments from command line

Posted by admin on October 23rd, 2010

This is a quick tip for all those beginers on openSUSE, SUSE Linux or even for that matter on any Linux or Unix distros on how to send an email from command line with an attachment. This could be a text or an image file.
By default, mail messages can be encoded with the file content into the mail message body rather than adding the required file as an attachment. To send a file as an attachment use the “uuencode” utility as follows:
Annai~ # uuencode filename.png filename.png | mailx -s “mail subject” receiver@address.com
In the above, uuencode writes an encoded version of the file (filename.png here) which is then piped to the mailx command.
This ofcourse assumes, you have your system is configured to send emails. In openSUSE, SuSE linux, click here to know how to configure Postfix to send emails.

6 Responses to “How to send email with attachments from command line”

  1. Rules of the game Says:

    much simpler:

    mail -s “subject” -a “filename”

  2. Rules of the game Says:

    mailx [-BDdFintv~] [-R address ] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[=value]] to-addr . . .

  3. darix Says:

    why so complicated?
    mutt -s subject -a file1 -a file2 receivert@example.com

  4. Sagi Says:

    You can also use mail , e.g. :

    # mail -a filename -s “you subject” mail@mail.com

  5. Will Stephenson Says:

    kmail –attach -s foo@bar.org does it too.

  6. aztrix Says:

    howzit folks?

    these tips are helpful but what i’ve been struggling with is trying to send spam email as an attachment to spamcop within kmail using the filter actions. Does anyone have any bright ideas to do this?

    cheers
    aztrix

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>