PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > How to type a message and also have an attachment with "mail"
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

How to type a message and also have an attachment with "mail"

Réponse
 
LinkBack Outils de la discussion
Vieux 20/08/2006, 02h34   #1
yusuf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to type a message and also have an attachment with "mail"

Hi,

Currently, I send the contents of a file by mail by typing:

mail someone@somewhere.com < some.file

But I can't type my own message using the above command to send with
the file. I checked the command line options for mail and there doesn't
seem to be an attachment parameter. Does anyone know how I can do this
through the command line?

Thanks.

  Réponse avec citation
Vieux 20/08/2006, 02h43   #2
joe@invalid.address
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to type a message and also have an attachment with "mail"

"yusuf" <yusufm@gmail.com> writes:

> Currently, I send the contents of a file by mail by typing:
>
> mail someone@somewhere.com < some.file
>
> But I can't type my own message using the above command to send with
> the file. I checked the command line options for mail and there doesn't
> seem to be an attachment parameter. Does anyone know how I can do this
> through the command line?


Take a look at Shelldorado it has scripts to do things like that.

http://www.shelldorado.com/

Joe
  Réponse avec citation
Vieux 20/08/2006, 03h20   #3
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to type a message and also have an attachment with "mail"

On 2006-08-20, yusuf wrote:
> Hi,
>
> Currently, I send the contents of a file by mail by typing:
>
> mail someone@somewhere.com < some.file
>
> But I can't type my own message using the above command to send with
> the file. I checked the command line options for mail and there doesn't
> seem to be an attachment parameter. Does anyone know how I can do this
> through the command line?


{
cat ## read stdin
cat some.file
} | mail someone@somewhere.com

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 20/08/2006, 14h57   #4
Matej Cepl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to type a message and also have an attachment with "mail"

yusuf wrote:
> Currently, I send the contents of a file by mail by typing:
>
> mail someone@somewhere.com < some.file
>
> But I can't type my own message using the above command to send with
> the file. I checked the command line options for mail and there doesn't
> seem to be an attachment parameter. Does anyone know how I can do this
> through the command line?


You have to either built whole MIME message (with all boundaries and
everything) and pipe it to /usr/bin/mail (or directly
to /usr/sbin/sendmail -- after all, when you built it all yourself there is
not much mail can do for you). The other way would be to use some other
mail replacement -- nail is 100% replacement of mailx and it can do (among
other things) attachments.

Matěj

--
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
http://www.ceplovi.cz/matej/blog/, Jabber: ceplma@jabber.cz
23 Marion St. #3, (617) 876-1259, ICQ 132822213

As a rule of thumb, the more qualifiers there are before the name
of a country, the more corrupt the rulers. A country called The
Socialist People's Democratic Republic of X is probably the last
place in the world you'd want to live.
-- Paul Graham discussing (not only) Nigerian spam
(http://www.paulgraham.com/spam.html)

  Réponse avec citation
Vieux 20/08/2006, 16h56   #5
Loki Harfagr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to type a message and also have an attachment with "mail"

Le Sat, 19 Aug 2006 22:20:00 -0400, Chris F.A. Johnson a écrit:

> On 2006-08-20, yusuf wrote:
>> Hi,
>>
>> Currently, I send the contents of a file by mail by typing:
>>
>> mail someone@somewhere.com < some.file
>>
>> But I can't type my own message using the above command to send with
>> the file. I checked the command line options for mail and there doesn't
>> seem to be an attachment parameter. Does anyone know how I can do this
>> through the command line?

>
> {
> cat ## read stdin
> cat some.file
> } | mail someone@somewhere.com


That's OK as the OP seems to send 7bit files (thru direct mail <)
but here's an idea of a small complement in case you have binaries.
I know it is dirty and it would be much better to use mimencode
than UUE but, that's for desperates cases where you don't have
metamail and you can't install them :-)
(besides if you have had metamail you would have used it
instead of this blob ;-)

-------------
$ cat mailx_in_shell
#!/bin/sh
###
Badfile () {
printf "\n\n File ${1} is empty or missing ...\n\n"
exit 2
}
Usage () {
printf "\n\n Usage: $0 adressee attachment\n\tType your message then Ctrl-D\n\n"
exit 1
}
###
[ $# -gt 1 ] || Usage
attachment="${2}"
adressee=${1}
sender="youlegaladdress@yourelayabledomain"
###
[ -s "${attachment}" ] || Badfile "${attachment}"
###
### This is if you post plaintext and dont need to send a binary
### ( printf "\n" && cat && cat "${attachment}" ) | /usr/lib/sendmail -v -f ${sender} ${adressee}
###
( printf "\n" && cat && printf "\n" && uuencode "${attachment}" "${attachment}" ) \
| /usr/lib/sendmail -v -f ${sender} ${adressee}

-------------
  Réponse avec citation
Vieux 20/08/2006, 22h00   #6
Martijn Lievaart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to type a message and also have an attachment with "mail"

On Sun, 20 Aug 2006 09:57:10 -0400, Matej Cepl wrote:

> You have to either built whole MIME message (with all boundaries and
> everything) and pipe it to /usr/bin/mail (or directly
> to /usr/sbin/sendmail -- after all, when you built it all yourself there is
> not much mail can do for you). The other way would be to use some other
> mail replacement -- nail is 100% replacement of mailx and it can do (among
> other things) attachments.


Handy! Thx.

M4
--
Ah, the beauty of OSS. Hundreds of volunteers worldwide volunteering
their time inventing and implementing new, exciting ways for software
to suck. -- Toni Lassila in the Monastry

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12857 seconds with 14 queries