How do I send a file as an email attachment using Linux command line?

后端 未结 26 2445
盖世英雄少女心
盖世英雄少女心 2020-11-22 04:39

I\'ve created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to .sql files and packages them togeth

相关标签:
26条回答
  • 2020-11-22 05:09

    metamail has the tool metasend

    metasend -f mysqlbackup.sql.gz -t backup@email.com -s Backup -m application/x-gzip -b
    
    0 讨论(0)
  • 2020-11-22 05:10

    Depending on your version of linux it may be called mail. To quote @David above:

    mail -s "Backup" -a mysqldbbackup.sql backup@email.com < message.txt
    

    or also:

    cat message.txt | mail -s "Backup" -a mysqldbbackup.sql backup@email.com 
    
    0 讨论(0)
  • 2020-11-22 05:11

    I use SendEmail, which was created for this scenario. It's packaged for Ubuntu so I assume it's available

    sendemail -f sender@some.where -t receiver@some.place -m "Here are your files!" -a file1.jpg file2.zip

    http://caspian.dotconf.net/menu/Software/SendEmail/

    0 讨论(0)
  • 2020-11-22 05:12

    using mailx command

     echo "Message Body Here" | mailx -s "Subject Here" -a file_name user@example.com
    

    using sendmail

    #!/bin/ksh
    
    fileToAttach=data.txt
    
    `(echo "To: user@company.com"
      echo "Cc: user@company.com"
      echo "From: Application"
      echo "Subject: your subject"
      echo  your body
      uuencode $fileToAttach $fileToAttach
      )| eval /usr/sbin/sendmail -t `;
    
    0 讨论(0)
  • 2020-11-22 05:13

    I use mpack.

    mpack -s subject file user@example.com
    

    Unfortunately mpack does not recognize '-' as an alias for stdin. But the following work, and can easily be wrapped in an (shell) alias or a script:

    mpack -s subject /dev/stdin loser@example.com < file
    
    0 讨论(0)
  • 2020-11-22 05:14

    From source machine

    mysqldump --defaults-extra-file=sql.cnf database | gzip | base64 | mail me@myemail.com
    

    On Destination machine. Save the received mail body as db.sql.gz.b64; then..

    base64 -D -i db.sql.gz.b64 | gzip -d | mysql --defaults-extra-file=sql.cnf
    
    0 讨论(0)
提交回复
热议问题