Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending email attachments with sendmail 1

Status
Not open for further replies.

MatthewP

Programmer
Jan 16, 2001
176
GB
Is there any easy way to attach files to emails using sendmail? So far the only answer I have seen is through installing the Mail::Sender module from CPAN, but unfortunately we dont have root access to achieve this. Surely there is another way?

Thanks,
matt.
 
uuencode [filename] [attachment name] ¦ sendmail [mail recipient] Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks Mike, any chance you could give me an example as I'm not really sure of the syntax.. do I leave the square brackets?

I tried the following (and a few other configurations) with no success...

uuencode myInFile.txt myOutFile.txt ¦ usr/bin/sendmail myEmail\@myDomain.co.uk;

Many thanks,

Matt.
 
Hi,

I still haven't got this to work and I've tried every configuration possible - would uuencode be disabled on some servers?

Thanks,
Matt.
 
hi mike

i am tyro in perl ,please tell me how to send attachments
in perl,java,c.also suggest if i am gonna my own mail server,whichone is better to use.
respond me as soon as possible.

sudhanshu mishra
 
Matt,

the problem is that normally you open sendmail "| sendmail ..." so that you can print information to it. with uuencode in front of the sendmail pipe, you'll have to do some trickery. try opening up a readable pipe over uuencode ("uuencode ... |") and reading in all the data from that, then printing this data to sendmail later when you're writing the rest of the normal sendmail information to it. i'm not too sure on how uuencode works, though - you may be able to write to the command Mike gave with just a '|' prepended onto it, and uuencode may properly pass this information on to sendmail. i doubt this, however, and would rely on my first suggestion or a permutation thereof...

good luck,
stillflame "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Hi Matthew,

what exactly have you tried with sendmail?
I can even attach several files using this:

uuencode file1 attach1 >> temp
uuencode file2 attach2 >> temp
...
cat temp | /usr/lib/sendmail address@something.com

Doesn't that work?
 
Wow! Took a couple of attempts, and required backticks in the Perl script, but yes that's it! Seems like it was just down to using backticks in the end.. duh!

Um.. I get a strange subject line though.. and idea how I change it?

Thanks everyone,
Matt.

PS - for anyone else reading this, a quick example of the version that worked...

#!/usr/bin/perl
print "Content-type:text/html\n\n";
`uuencode index.html myfile.html >> temp`;
`cat temp | /usr/lib/sendmail mattplatts\@beeb.net`;
print "mail sent!\n";

 
hmm. rather than doing the second line with the 'cat temp' part, try opening up a sendmail pipe, printing to it the 'To:', 'Subject:', &c. parts, then opening up the temp file you made with uuencode, and printing it into the sendmail pipe. you may have to have a different header on the body of your mail ('multi-part/form' maybe?), but that way you'll have control over the subject line of the mail. also, i think you can include a subject in the initial calling of sendmail, which you could more easily encorporate into your script. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Stillflames approach sounds the best one Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top