1761280 Members
4572 Online
108901 Solutions
New Discussion юеВ

Mail from command line

 
SOLVED
Go to solution

Mail from command line

I want to send file attachments from the commandline (sendmail)
currently i have only found syntax for elm to send a file as an email not as an attachment.
The sysntax i have used is :-
elm -s "subject" User@server < filename

can anyone tell me how to send tha file as an attachment please

Thanks
10 REPLIES 10
Charles Harris
Super Advisor

Re: Mail from command line

This is the hunt for the holy grail as far as I'm concerned, I have included a file in the body of an email but never as a real attachment. I've asked quite a few people about this and the general responce is that it can't be done (with mailx) at least, wether or not this is true remains to be seen, although I'll be watching closely to see where this one goes!!!


Cheers,


-ChaZ-
Thierry Poels_1
Honored Contributor

Re: Mail from command line

Hi,

(cat text; uuencode file1 file1)| mailx user

this example will send a text with an attachement.
good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Pedro Sousa
Honored Contributor

Re: Mail from command line

Hi!
mailx -s "" address <
good luck.
federico_3
Honored Contributor
Solution

Re: Mail from command line

CHRIS ANORUO
Honored Contributor

Re: Mail from command line

Try these command:
unencode localfilename attachedfilename |sendmail user@hp.com or
unencode localfilename attachedfilename |mailx user@hp.com
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Jim Moffitt_1
Valued Contributor

Re: Mail from command line

This has worked for me:

first create a dummy file:
# cat /tmp/dummy
[include /tmp/jimbackup.010208.5037.log application/msword base64]

Then issue the elm command:
elm -s 'test' jim_Moffitt@notes.teradyne.com < /tmp/dummy
This has worked for me without any problems.

Jim
Rita C Workman
Honored Contributor

Re: Mail from command line

There are a few ways you can do this. Chris mentioned uuencode, and here's a thread that rementions that along with my personal favorite the [include statement] along with another way to do this using mpack. Hope it helps you:

http://my1.itrc.hp.com/cm/QuestionAnswer/1,1150,0x41950559ff7cd4118fef0090279cd0f9!0,00.html

Regards,
/rcw
Shannon Petry
Honored Contributor

Re: Mail from command line

The problem that you will have trying to re-invent the wheel is that sendmail can handle a mime-encoded attachment ONLY! You can not send raw binary data via email no matter what!!!!!!!!!!!!!!!!!!

This forces many steps!
1. mime-encode your file and put it somewhere. (This is more daunting than it appears as there is no mimencode by nature on HP-UX, and the one on the porting center is partially broken!)

2. build a file for sendmail which contains the required size, mime-type, and of course syntax for the attachment, and anything else you need with it. I.E. Subject, Message Body, etc.... Sendmails syntax, and requirements for empty lines for this is not easy by any means!

There is a patch for ELM on HP-UX which allows attachments with a single file line with the attachment and mime-type.

mail, mailx, and standard elm dont support binary file attachments, only text which is placed as the message body. I.E.
mailx -s 'subject' someone@dom.com < /tmp/mailfile.txt

I use the patched elm to send binary attachments where necessary, and include the "include" statement within scripts to make it on the fly and control file names, etc....

Literally I spent 2 days trying to get sendmail to work with the attachments, get a mime encoder working, and only about 20% of the mails worked. Too much work re-inventing the wheel for me!

Regards,
Shannon
Microsoft. When do you want a virus today?

Re: Mail from command line

Thanks for you help everyone.

I have a soloution with mpack.

Just one more question on this , is there any way to send multiple attachments.
My current soloution is to tar the files I want to send, but this could be a problem when sending out to user with a lack of winzip or similar.

Any suggestions ??

Once again, everyone thanks for you help