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

后端 未结 26 2442
盖世英雄少女心
盖世英雄少女心 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:03

    You can use mutt to send the email with attachment

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

    Mailutils makes this a piece of cake

    echo "Body" | mail.mailutils -M -s "My Subject" -A attachment.pdf mail@example.org
    
    • -A file attaches a file
    • -M enables MIME, so that you can have an attachment and plaintext body.

    If not yet installed, run

    sudo apt install mailutils
    
    0 讨论(0)
  • 2020-11-22 05:05

    None of the mutt ones worked for me. It was thinking the email address was part of the attachemnt. Had to do:

    echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.com
    
    0 讨论(0)
  • 2020-11-22 05:05

    I used

    echo "Start of Body" && uuencode log.cfg readme.txt | mail -s "subject" "a@b.c" 
    

    and this worked well for me....

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

    Just to add my 2 cents, I'd write my own PHP Script:

    http://php.net/manual/en/function.mail.php

    There are lots of ways to do the attachment in the examples on that page.

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

    Not a method for sending email, but you can use an online Git server (e.g. Bitbucket or a similar service) for that.

    This way, you can use git push commands, and all versions will be stored in a compressed and organized way.

    0 讨论(0)
提交回复
热议问题