<<< Date Index >>>     <<< Thread Index >>>

Re: sending attachments from commandline



* René Clerc <rene@xxxxxxxx> :
> * Troy Piggins <troy@xxxxxxxxx> [07-09-2005 00:28]:
> 
> > I have done some googling, and understand that the following
> > should send a mail with attachments from the commandline without
> > interaction required from the shell.  Trouble is, I can't get it
> > to work.  I want to use a similar line in a script - the <
> > /dev/null gives me an empty message body which is fine, I just
> > want the attachment.
> > 
> > mutt -s "testing attachments" -a sample.txt troy@xxxxxxxxxxxxxxxxxxxxx \
> >   < /dev/null
> > 
> > As soon as I take away the -a an argument, it works.
> 
> That is strange, because I too believe that this should work.  I use
> the following in a shell script daily:
> 
> /usr/local/bin/mutt -n -e "my_hdr From: noreply <devnull@xxxxxxxx>" \
>   -s "SUBJECT" -a dirkjan.jpg -a djanko.jpg -a stamgasten.jpg \
>     -e "fcc-hook .* /dev/null" $EMAIL_RECIPS < /dev/null
> 
> Does adding "-n" make a difference?

No, -n didn't make a difference.  

** Never mind, I think I solved it - read my last paragraph here if
you want to skip this middle stuff.  **

I shouldn't have over-simplified my example.  The file I tried to
attach is actually a .zip file about 1.9Mb.  I just tested smaller
file (text only) about 2kb and it did in fact work ok.

Reason I am asking is that I am working on a script that uses
procmail to detect if there is a winmail.dat attachment.  If there
is, it saves the file using munpack, converts it to its correct form
using tnef, and then I wanted to email the correct attachment to
original recipient.  So the filetype could be anything, just so
happens that most of the time it will be a .zip file quite large.

The script works right up to the part where I am trying to email the
unpacked and un-winmail.dat'ed file.

> > If I use an invalid recipient, I get an error message - so I figure
> > the mail is at least going somewhere.
> 
> Now you've lost me.  What is an "invalid recipient"?  An e-mail
> address that is not used?  A wrongly formatted e-mail address?
> Furthermore, what is the error message?  Is it an error e-mail
> message?  What makes you think the mail is going somewhere?

Sorry.  "Invalid recipient" means something like
"fred@xxxxxxxxxxxxxxxxxxxxx" where fred is not a valid user.  The
email address is correctly formatted.

The error message was (extract):

-----
From: Mail Delivery System <MAILER-DAEMON@xxxxxxxxx>
Subject: Undelivered Mail Returned to Sender
Date: Wed,  7 Sep 2005 23:49:29 +1000 (EST)
To: troy@xxxxxxxxx

[-- Attachment #1: Notification --]
[-- Type: text/plain, Encoding: 7bit, Size: 0.4K --]

This is the Postfix program at host armadillo.piggo.dyndns.org.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                        The Postfix program

<fred@xxxxxxxxxxxxxxxx>: unknown user: "fred"
-----

Now this is with the large .zip file attachment.  So it is getting
sent by mutt - so I am starting to think it is a postfix problem,
not a mutt one.

> > When I execute the commandline with an attachment about 1Mb, there
> > is a slight pause after the command is executed - I assume this is
> > mutt attaching the file and sending it.
> 
> Was this with or without supplying a (in your terms) "valid"
> recipient?

Both cases.  See above.

> > But it never seems to get delivered anywhere.  What am I missing?
> 
> You could check your MTA's logs (if you have access to them)..
> 
> Please elaborate some more..

Ok, checked the postfix logs.  To be honest I assumed it was a mutt
problem.  Anyway, postfix logs said it was getting sent and
delivered to procmail.  So I checked the procmail logs, and
somewhere in there it was getting delivered to /dev/null because the
hostname of the machine is not whitelisted by my own procmail rules.
So after all that it was a procmail problem created by me.

Never mind, all sorted now.  THanks anyway.

-- 
Troy Piggins - Been a novice linux user since 1998
             - When do I become an expert?
RedHat 9: mutt 1.5.9i, procmail 3.22, postfix 2.2.4, slrn 0.9.8.1,
          vim 6.1, kernel 2.4.20-31.9