I am trying to send an attachment via a script and the logic works if i run manually but not as part of the script. if I add echo, the email goes out and populates with uuencode jef20.txt jef20.txt but no attachment. any ideas?
#!/bin/bash
echo Your Username?
read user
echo FIX Session?
read session
echo what client?
read client
awk '!/35=0|35=A|35=5|35=2|35=1|closed/' /company/gate/app_phoenix/logs/fix/$session >> /home/dnash/$client.txt
uuencode $client.txt $client.txt | mailx -s "Cert Logs" "$user#company.com"
Depending on your version of mailx , you can use the -a ( "attach" ) command line switch:
mailx -a "$client.txt" -s "Cert Logs" "$user#company.com"
See Also
mailx manpage
how to send an email via mailx with enclosed file
Related
I am trying to sending mail with attachment using shell script, but I am not getting mail.
Shell Script
#!/bin/bash
$ echo "Mail Sent" | mail -s "a subject" -a "Report_by_Customer_20190614_131246.xls" test#gmail.com
Use mutt. Add list of files that you want to attach
echo "body" | mutt -s "subject" -a attachment0 attachment1 [...] -- test#gmail.com
Also here you can find another options
i have a bash script with the below contents
#!/bin/bash
mv /test.txt/ /test/date "+%d-%m-%y"`.txt
Need to attach this file using mutt and send an email.
Kindly help
-a to attach a file
mutt -s "mail subject" example#address.com < /path/to/message/body.txt -a /path/to/text.txt
Our production server has been retired and now we are using a hosted system running Redhat GNU/Linux.
We had many scripts using mutt to send file attachments but they're failing now since mutt is not installed on our servers (The sysadmin policy is that mutt is not secure so it will not be installed)
I have tried using mailx but to no avail. When I do
echo "this is my email body"| mailx -s "this is my email subject" "email#xyz.com" -a "filename.csv"
I get
$ send-mail: illegal option -- a
"filename.csv" exist and it is local to the directory I run the command from. Of course, when I do
mailx -s "this is my email subject" "email#xyz.com" < "filename.csv"
It works but it embeds the file attachment in the email body. Users do not want that.
What am I doing wrong?
I figured it out. I simply moved the -a flag before the email address like so
echo "this is my email body"| mailx -s "this is my email subject" -a "filename.csv" "email#xyz.com"
It worked just fine.
uuencode filename.csv filename.csv | mailx -s "this is my email subject" "email#xyz.com"
Or, if you want to clump text and an attachment together, then
echo "this is my email body" | cat -<(echo uuencode filename.csv filename.csv) | mailx -s "this is my email subject" "email#xyz.com"
I came across the same problem, use -A instead of -a. It worked for me.
I'm trying to send an email in this way:
path_to_file="/home/username/tmp/filename.html"
subject="My Subject"
to.each do |address|
cmd = "`echo \"#{body}\" | mutt -s \"#{subject}\" #{address} -a #{path_to_file}`"
system(cmd)
end
end
This is running on a unix machine, the file has an html extenxion and contains html code.
I receive the file correctly, with the same filename and extension, the problem is that is completely empty, this is strange because when i run the same command (mutt) from the terminal, applying the same path to file:
echo "body here" | mutt -s "some subject" mamail#mail.com -a ${path_to_file}
Then it works just fine.
Any idea?
I am trying to run a long bash script overnight to get some data. I wanted to include a script that would automatically e-mail me the files after the scripts are completed. Is there a way to do this using mutt? I want something like below:
sh atoms.sh
sh angles.sh
mutt -a atoms.dat angles.dat -- [e-mail adress]
Any takers?
EDITS: If there's any other way to achieve this -- "sending multiple attachment to an e-mail address after scripting is finished" -- I'd be very appreciated.
sh atoms.sh
sh angles.sh
mutt -s "data set from atoms.sh" [email address] < ./atom.dat
mutt -s "data set from angles.sh" [email address] < ./angles.dat
will disable the terminal interaction and send e-mails after the jobs are finished
-a file [...]
Attach a file to your message using MIME. To attach multiple files, separating
filenames and recipient addresses with "--" is mandatory, e.g. mutt -a img.jpg
*.png -- addr1 addr2.
$ $( sh atoms.sh; sh angles.sh ) && mutt -s "man mutt" \
-a grab.sh raptor.mpd.ogg.m3u scripts/bussorakel \
-- emailAddress#example.com < /dev/null
alternatively, you have:
$(sh atoms.sh; sh angles.sh ) & FOR=$!
wait $FOR
mutt -s "last command done, sending email" (...)