Multiple attachments using mutt


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Multiple attachments using mutt

I am trying to attach multiple files using mutt command, and all file names to be attached are taken from a flat file. and mutt command is called from a bash script when :

1. Script execution is completed.
2. Script execution is interrupted for some reason.

-------------------------------------------------------------------
Code:
Contents of REPORTS.LOG:
/home/jboss/temp/a.html
/home/jboss/temp/temp/b.html

TOTAL_REPORTS=`cat REPORTS.LOG | wc -l`
for (( i=0; i<$TOTAL_REPORTS; i++ ))
do
        a[i]=`sed -n "$((i+1))""p" "REPORTS.LOG"`
        attachments=( "${attachments[@]}" "`echo "-a ${a[i]} "`")
done
cat XYZ.LOG | mutt `echo "${attachments[@]}"` -s "Test" -b a@b.com

Issue is :

Sometimes code is executed appropriately and attachments are seen in the email whereas sometimes email is received without attachments and attachmens' file path are seen as broken string in as :

From : jboss@172.19.10.55
To : -@172.19.10.55;/home/j@172.19.10.55;...0.55;mp/a.html@172.19.10.55;
[PLEASE SEE THE HIGHLITED PATH ABOVE]

Last edited by Shaishav Shah; 12-19-2012 at 03:10 AM.. Reason: Better understanding
# 2  
This User Gave Thanks to DGPickett For This Post:
# 3  
Thanks DGPickett.

I shall try this now.

---------- Post updated at 12:55 PM ---------- Previous update was at 11:09 AM ----------

Not sure what's going wrong. Above solution works independently when run as a stand-alone command , but when run from within the script, it fails and no attachments are seen in the email. What we get is as mentioned above.

Any solution please........

---------- Post updated at 03:45 PM ---------- Previous update was at 12:55 PM ----------

It works when we change the order of mutt switches, i.e. put attachments at last.
Code:
cat XYZ.LOG | mutt  -s "Test" -b a@b.com `echo "${attachments[@]}"`


Last edited by Franklin52; 12-20-2012 at 07:28 AM.. Reason: Please use code tags for data and code samples
# 4  
Maybe someone is gobbling up the -- or something like that. In some situations, the shell quotes together the subshell output, so passing it through a variable or function call may be needed to break it up. You can put a "truss/strace/tusc -fae -o /tmp/mutt.$$.tr" prefix on mutt in the shell script and see in detail what the actual call is like. Putting the attachment list last is a nice workaround, though.
# 5  
The workaround of putting attachments list at last does not work always. There is something that breaks the attachments and appends ip to broken substrings but not sure what Smilie
# 6  
Again, strace/truss/tusc can tell you what is happening and what is being called. mutt should work if the command line and environment are preserved.
# 7  
Computer Using sendmail

Code:
#!/bin/ksh
{
        # ------------------------ #
        # --- Sendmail Headers --- #
        # ------------------------ #
        echo "From: sender@domain.com"
        echo "To: recipient@domain.com"
        echo "MIME-Version: 1.0"
        echo "Subject: Test mail attachment"
        echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
        echo "---q1w2e3r4t5"

        # ------------------------ #
        # ---- Sendmail Body ----- #
        # ------------------------ #
        echo "Content-Type: text/plain"
        echo "Content-Disposition: inline"
        echo '---q1w2e3r4t5'
        cat XYZ.LOG
        echo '---q1w2e3r4t5'

        # ------------------------ #
        # - Sendmail Attachments - #
        # ------------------------ #
        while read file
        do
                echo "Content-Type: text/plain; charset=US-ASCII; name=$file"
                echo "Content-Disposition: attachment; filename=$file"
                echo '---q1w2e3r4t5'
                cat $file
                echo '---q1w2e3r4t5'
        done < REPORTS.LOG
        echo '---q1w2e3r4t5--'
} > sendmail.txt

/usr/lib/sendmail -t < sendmail.txt

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #327
Difficulty: Easy
The Windows 7 operating system has seven main editions.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Attach multiple index.html file using mutt

Hi I want to attach multiple index.html, index_v2 file using mutt command basically i want first index.html and then index_v2.html file as a body in email , these html files are test reports I am using following command , but it is over writing , any help appreceated ;) mutt -e... (2 Replies)
Discussion started by: madankumar.t@hp
2 Replies

2. UNIX for Advanced & Expert Users

Mutt for html body and multiple html & pdf attachments

Hi all: Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project. There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues. Running with... (1 Reply)
Discussion started by: raggmopp
1 Replies

3. Shell Programming and Scripting

How to send email with multiple attachments ?

Hello , I am trying to send an email with two attachments . I have tried all previous suggestion in this forum but none worked. I could send one attachment in an email by uuencode $file "$file" | mailx -m -s "File" xxx@xx.com but unable to send multiple attachments . I have tried ... (8 Replies)
Discussion started by: RaviTej
8 Replies

4. Shell Programming and Scripting

Problem with multiple mail attachments

Hi everyone... I am facing problem with the multiple mail attachments. cd /work/mohan/pi_log/ mail_file='uuencode ahmedabad.csv ahmedabad.csv ; uuencode ahmedabad_devrpt_20110530.csv ahmedabad_devrpt_20110530.csv' ( $mail_file ) | mailx -m -s"test" domain@website.com its giving me error... (1 Reply)
Discussion started by: mohanm
1 Replies

5. UNIX and Linux Applications

Attachments in MUTT.

Can any body figure out how to attach the attachments mails while drafting them in MUTT form any location on my system. I am not able to figure it out. (0 Replies)
Discussion started by: nixhead
0 Replies

6. Shell Programming and Scripting

How to attach multiple .csv files using mutt command

I need to attach all files starting with 'BusinessReport' using mutt command. It could be any number of files in that directory, say BusinessReport_01, BusinessReport_03, BusinessReport_04 etc. Is there a way to attach all files where filename like BusinessReport_* and sent it using mutt... (2 Replies)
Discussion started by: Jassz
2 Replies

7. Shell Programming and Scripting

E-mailing Multiple Attachments in AIX

Hello Everyone, I'm trying to write ascript on AIX 5.3, that will e-mail all filles within a directory. But on executing a script , it sends only 1 file from the directory alongwith some Junk data. I have searched whole forum and almost used all the suggestions, but still getting same problem.... (4 Replies)
Discussion started by: Gem_In_I
4 Replies

8. Shell Programming and Scripting

Sending multiple attachments

Hi people, I am new to this forums. I have a quick question I hope one of you could help me with. I am writing a script to send attachments via email. However I am having trouble when trying to send multiple attachments. Here is the code I am using: send_mail() { uuencode $TMP $TMP1 > $TMP1... (1 Reply)
Discussion started by: deo2k8
1 Replies

9. Answers to Frequently Asked Questions

multiple attachments

how can you send multiple attachments in 1 email, usually I just use uuencode to send 1 attachment. thanks (5 Replies)
Discussion started by: edog
5 Replies

10. How do I send email?

multiple attachments

how can you send multiple attachments in 1 email, usually I just use uuencode to send 1 attachment. thanks (5 Replies)
Discussion started by: edog
5 Replies

Featured Tech Videos