Hi, I have searched the site for info on sending an attachment in Linux, have tried a few people mailx codes but to no success. Can someone please help me? This is what i have so far:
#!/bin/bash
user_mail_address="me@yahoo.com"
filename="attachment.txt"
body="This is the body"
mail -s "This is the subject" $user_mail_address $filename
How do i modify the code, so that I can add a file attachment.txt and also type something in the body of my email? Thanks.
Yes, I have tried a few of them. They used mailx instead of mail. Also, once I ran their scripts, its waiting for me to input something. So I typed in a letter or a filename, but it still continue to wait for an input. I had to press control C to exit. Then it says --interrupt once more to kill.
I will continue to search, but so far no luck yet after looking at many threads. Here are a couple of codes from different folks that doesn't work for me. It just wait for me to input something in the terminal:
CODE#1
( cat a
uuencode b.txt
) | mail -s "Attachment Sent" $mail_user
CODE#2
(echo "`cat a`"; uuencode t /home/lang/script/b.txt) | mail -s "Attachment Sent" $mail_user
the command to send a file as body of the e-mail is #mailuser@e-mail.com -s 'hosts file' < /etc/hosts
this will show the file etc hosts as the contents of the email and hosts file in the subject line.
try something along these lines #mailuser@e-mail.com -s "Attachment Sent" < /home/lang/script/b.txt
but this will only give you a nice email with filecontentsforbody.txt as the email body. I don't know how to attach somefile.zip or whatever to your email.
Thanks to everyone who replied. What happened to my Linux is my root user told me that I need a reboot. After the reboot, then my email with attachment works. Here's my code with a subject, body, and an attachment:
(echo "This file $FILE was sent from Linux."
for i in `ls -1 $FILE`
do
file_name=`basename $i`
uuencode $i $file_name
done
) | mail -s "Mail sent with the attachment file: $FILE" "$RECIPIENT"
To use this script, just type in the name of the script followed by the filename. I thought I'd share this because I had a hard time getting to this point