Will Yardley <mutt-us...@veggiechinese.net> writes:

>On Sat, Dec 01, 2012 at 05:12:05AM +0000, Jeffery Small wrote:
>> Within a script, I would like to use mutt to automatically email a JPEG
>> file as an attachment without user intervention.  Is there any way to
>> accomplish this?  (And if not with mutt, then possibly with mail(1) or
>> mailx(?))
>> 
>> When I try to use the -a option to mutt, it always responds: "unable to
>> attach file".
>> 
>> Also, from the commandline, I don't know how to tell mutt to base64 encode
>> the file.  I could encode the file manually before passing it to mutt, but
>> I'm still at a loss as to how to get mutt to properly attach it to the
>> message.

>You shouldn't need to do any special encoding, and mutt -a should do
>what you want.

>What is the exact command line you're using, and what's the *full*
>error? Searching for the error message you're getting briefly, it looks
>like this error may come up when the -a argument is specified before the
>recipient rather than after (and if that's the case, you'll notice that
>the recipient address, rather than the filename, is what it can't
>attach). Otherwise, it could be a permissions or file path related
>problem.

>Something like this should work:
>% echo 'This is my body' | mutt -s 'file attached' \ 
>      m...@example.com -a image001.jpg 

>Whereas this gives an error:
>% echo 'This is my body' | mutt -s 'file attached' -a \
>   image001.jpg m...@example.com
>Can't stat m...@example.com: No such file or directory
>m...@example.com: unable to attach file.

Will:

Thanks so much for your quick reply.  You are exactly right, the problem was
that the -a <file> argument was before the address argument and it was taking
the address as a file to be attached.  I was confused by the error message
because when it gave the message (using your example):

        m...@example.com: unable to attach file.

I thought the "m...@example.com:" part was simply identifying the recipient
and that it was complaining about the other file being unable to be
attached.  I didn't realize that this was trying to tell me that it thought
"m...@example.com" was a non-existent file.

I was further confused because it turns out that there is also an older 1.4
version of mutt on this machine, and when I read the manual page, I was getting
the old documentation.  This read:

mutt  [-nx] [-e cmd] [-a file] [-F file] [-H file] [-i file]
      [-s subj] [-b addr] [-c addr] addr [...]

which clearly shows the -a option before the address and with only a single
file argument.  When I corrected things and got to the proper manpage, it 
reads:

mutt [-nx] [-e cmd] [-F file] [-H file] [-i file] [-s  subj]
     [-b addr] [-c addr] [-a file [...] --] addr|mailto_url [...]

which shows the support for the multiple arguments to the -a option, which
can be terminated with "--" which also works in my tests.

I'm back in business thanks to your help which is very much appreciated.

Regards,
--
Jeffery Small

Reply via email to