Question

send mail with attachments from UNIX server to Windows

Asked by: rvsBhanu

can someone help with the script/command required to send a mail with attachment from a UNIX server to Windows mailbox.Is there any additional configuration that needs be done on the UNIX box for this ?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-12 at 06:37:37ID24563448
Topics

Unix Systems Programming

,

SendMail Email Server

,

Exchange Email Server

Participating Experts
2
Points
125
Comments
44

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. unix mail
    Can someone tell me how to attach( not redirect using "<") a file in Unix mail.
  2. Attaching Files to Mail in Unix
    I am creating a shell script which concatenates a few files. Then if the file exists and has a size greater than 0 I want to email a couple of files. My problem is that I can't figure out how to attach the files. I don't want to just include the contents of the files withi...
  3. Mail Attachments from Unix
    Hi all, I am trying to send binary attachments from unix shell script. Our Unix is Digital tru64. So, I am searching for default mime encoder. Can any body help me out. What is the default mime encoder which I can use to send mail attachments in Digital tru64 Unix ? Than...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: KeremEPosted on 2009-07-12 at 06:50:58ID: 24834398

Hi,

If all you would like to send as an attachement is a file and you don't need MIME encoded attachement you can do it like that:

uuencode reports.tar.gz reports.tar.gz | mailx -s "My Report" user@yourcorp.com

Or

$ (cat mymessage.txt; uuencode file1.jpeg file2.jpeg) | mail -s "Subject" user@example.com

Bif you need MIME than you need to use some program like mutt.

Cheers,
K.

 

by: rvsBhanuPosted on 2009-07-12 at 07:11:13ID: 24834441

thanks...

I would normally like to send an excel sheet as an attachment.
would this command work out for that....or do I need mutt..?

 

by: KeremEPosted on 2009-07-12 at 07:19:03ID: 24834468

Yup. you can simply do this:


uuencode sheet1.xls | mailx -s "My report sheet" user@example.com

This will send your report. If you don't have uuencode installed on your system it comes with sharutils package so try to install it.

Cheers,
K.

 

by: rvsBhanuPosted on 2009-07-12 at 07:29:48ID: 24834502

can u also tell me from where I can install the uuencode or where I can get the sharutils package ?

 

by: KeremEPosted on 2009-07-12 at 07:35:02ID: 24834517

ooops sorry you need to rpeat the name twice:

uuencode sheet1.xls sheet1.xls | mailx -s "My report sheet" user@example.com

 

by: KeremEPosted on 2009-07-12 at 07:38:09ID: 24834524

What distro are you using ??

 

by: rvsBhanuPosted on 2009-07-12 at 08:16:57ID: 24834634

sorry...distro...could not get that..?

 

by: KeremEPosted on 2009-07-12 at 08:25:03ID: 24834660

What Brand UNIX are you using ? If it is LINUX what distirbution of LINUX are you using?

Different unicies have different installation instructions or resources to install

 

by: rvsBhanuPosted on 2009-07-12 at 08:33:18ID: 24834698

not really sure of that...where can I check that ?

 

by: rvsBhanuPosted on 2009-07-12 at 08:36:54ID: 24834716

I mean where can I check the type of distribution ?

 

by: KeremEPosted on 2009-07-12 at 09:07:41ID: 24834802

just issue

uname -a

and post the result here.

 

by: rvsBhanuPosted on 2009-07-12 at 09:16:43ID: 24834825

I need to go to my workplace and check for it.
Will post the results for it by tomorrow same time...

thanks a lot for ur time on this..

 

by: KeremEPosted on 2009-07-12 at 13:15:05ID: 24835641

Yr welcome take your time and let me know.

 

by: rvsBhanuPosted on 2009-07-13 at 08:04:14ID: 24840379

% uname -a
SunOS dvc7600 5.9 Generic_118558-38 sun4u sparc SUNW,Netra-T12

 

by: omarfaridPosted on 2009-07-13 at 08:17:03ID: 24840522

uuencode is available on solaris, did you try to run it?

you could try to find it with

which uuencode

or

find / -name uuencode

it should be under /usr/bin dir

 

by: rvsBhanuPosted on 2009-07-13 at 08:32:28ID: 24840706

I am able to send/receive the mail,but without any attachments...

Can you let me know wat needs to be done for getting the attachments as well..??

 

by: rvsBhanuPosted on 2009-07-13 at 08:39:42ID: 24840767

Thanks all...I am able to send mail with attachement.

Is there any way that it can be automated ?as in....at a particular time of the day a mail is fired to a mail address with the daily excel as an attachement ?This daily excel has a particular format ie.rptjul1309...a simialar file is created for each day with the suitable date...

 

by: omarfaridPosted on 2009-07-13 at 08:57:03ID: 24840949

- you can create a shell script e.g. myscript that contains

/usr/bin/uuencode /path/to/sheet.xls sheet.xls | /usr/bin/mailx -s "put subject here" username@domain.com

- make the script executable

chmod +x /path/to/myscript

- create a crontab job

crontab -l > mycrom
echo '0 21 * * * /path/to/myscript' > mycron
crontab mycron

here the script will run daily at 9:00 PM

for more help run

man crontab

 

by: rvsBhanuPosted on 2009-07-13 at 11:08:12ID: 24842260

the excel is not static data here. everyday a new excel file with a different name(as in the name would have a different date appended for each day)would be uploaded at the particular location and I need that to be sent by this job.

Would the above solution work for that ?

 

by: KeremEPosted on 2009-07-13 at 11:20:23ID: 24842383

Yeah you can just create the script I'll gve an example below. Then put it in cron as OmerFarid indicated and you're done.


#!/bin/sh
 
export RPTNAME="rpt$(date +%b%d%g).xls"
 
uuencode $RPTNAME $RPTNAME | mailx -s "Contains report file $RPTNAME" user@example.com
                                              
1:
2:
3:
4:
5:

Select allOpen in new window

 

by: rvsBhanuPosted on 2009-07-13 at 11:25:03ID: 24842423

here,where do I specify the location of the excel ,from where it is to be pulled ?

 

by: KeremEPosted on 2009-07-13 at 11:45:36ID: 24842628

export RPTNAME="rpt$(date +%b%d%g).xls"

This line is creating the name of the file form the current date. For today the name will be:

rptJul1309.xls

%b means short month name such as Jan, Jul, Oct etc.
%d means the day part of the date in the format 00..31
%g means two digit year 00.99

So the name is created. then it will uuencodeand send the named file with the next line:
uuencode $RPTNAME $RPTNAME | mailx -s "Contains report file $RPTNAME" user@example.com

 

by: rvsBhanuPosted on 2009-07-13 at 11:51:45ID: 24842685

thx...understood this...
wat I wanted to ask was where do I specify the path of the excel file as in ,can it be :

uuencode /path/to/$RPTNAME $RPTNAME | mailx -s "Contains report file $RPTNAME" user@example.com

Is this correct ?

 

by: KeremEPosted on 2009-07-13 at 12:24:07ID: 24842982

Yeah this is correct you can specifty the path like that

uuencode /path/to/$RPTNAME $RPTNAME | mailx -s "Contains report file $RPTNAME" user@example.com

you don't need to modify the second one since it is to put in the encoded text as filename.

 

by: rvsBhanuPosted on 2009-07-16 at 08:49:03ID: 24870374

is there any way where I can send two files from two different locations as attachments in the same mail ?

 

by: omarfaridPosted on 2009-07-16 at 11:57:35ID: 24872472

tar the two files into one tar file, then compress the tar file then send it:

- tar cf myfiles.tar /path/to/file1 /path/to/file2
- gzip myfiles.tar
- cat myfiles.tar.gz | uuencode myfiles.tar.gz | mailx -s "two files attachment" username@domain.com

 

by: rvsBhanuPosted on 2009-07-17 at 08:00:09ID: 24879296

Thanks..
Now the thing is I need this file : myfiles.tar to be variable as in file1 and file2 are daily generated .

So is there some way by which it creates the tar file as variable or deletes the file everyday once the mail is sent ?

 

by: KeremEPosted on 2009-07-17 at 08:41:31ID: 24879760

Hi,

This will do.

#!/bin/sh
 
export RPTNAME="rpt$(date +%b%d%g).tar"
 
tar cf $RPTNAME.tar /path/to/files
 
uuencode $RPTNAME $RPTNAME | mailx -s "Contains report file $RPTNAME" user@example.com

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: KeremEPosted on 2009-07-17 at 08:42:00ID: 24879766

Sorry my bad try this instead:

#!/bin/sh
 
export RPTNAME="rpt$(date +%b%d%g).tar"
 
tar cf $RPTNAME /path/to/files
 
uuencode $RPTNAME $RPTNAME | mailx -s "Contains report file $RPTNAME" user@example.com

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: KeremEPosted on 2009-07-17 at 08:52:02ID: 24879852

You might also like to use the code below. Will you tell what will be the namses for the files? Are there rules to know what will be the file names to go in the attachment ?

#!/bin/sh
 
export RPTNAME="rpt$(date +%b%d%g)"
 
 
mailx -s "Contains report file $RPTNAME" kerem@sibernet.com.tr << END
$(uuencode file1.xls  file1.xls)
$(uuencode file2.xls file2.xls)
END

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: rvsBhanuPosted on 2009-07-17 at 10:52:08ID: 24881009

yes,the two excel files that I need to be attached will have a particular format ie. devidrpt<mmmddyy> and nondevidrpt<mmmddyy>.

Also let me know where do I specify the path to these files as both these files would be at different location ?

 

by: KeremEPosted on 2009-07-17 at 11:04:38ID: 24881152

Here is the info.

You need to add the path before the first occurrence of file name after the uuencode command:

#!/bin/sh
 
export RPTNAME="$(date +%b%d%g)"
 
 
mailx -s "Contains report file $RPTNAME" user@example.com << END
$(uuencode /path/to/devidrpt${RPTNAME}.xls  devidrpt${RPTNAME}.xls)
$(uuencode /ot/path/to/nondevidrpt${RPTNAME}.xls  nondevidrpt${RPTNAME}.xls)
END

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: rvsBhanuPosted on 2009-07-17 at 11:53:17ID: 24881628

the above code gives the below error:

RPTNAME=$(date +%b%d%g): is not an identifier

any idea wat is causing the issue ?

 

by: KeremEPosted on 2009-07-17 at 13:04:26ID: 24882359

Hi,

I guess your shell is different then mine try to modify this line:

export RPTNAME="$(date +%b%d%g)"

as

RPTNAME="$(date +%b%d%g)"
export RPTNAME

Cheers,
K.

 

by: rvsBhanuPosted on 2009-07-19 at 17:03:14ID: 24891676

thanks...
I already have a script for modifying the attachement name as per the date.

I would like to know how can I send the two attachments(excel) from two different locations in one mail.And since these are excel files in binary format, any mechanism to convert the binary to excel format for easy viewing.

 

by: KeremEPosted on 2009-07-19 at 17:14:28ID: 24891701

@rvsBhanu
> I would like to know how can I send the two attachments(excel) from two different locations in one
> mail

Did you notice the encoding part in my script:

the line 2 sends the file in /path/to/file/devidrpt${rptname}.xls
while the line 3 sends /ot/path/to/nondevidrpt${RPTNAME]}.xls

As you see you can modify the paths as you wish.

> And since these are excel files in binary format, any mechanism to convert the binary to excel format for easy viewing.

You've lost me completely. Yes excel files are in binary format. There is no such thing as non-binary excel format. Do you mean CSV (Acronym for Comma Separated Values)  when you say binary to excel format ? Or do you mean you need some your binary to .xls format? Then what is the format that your binaries are kept? What application generates it? May be this application has a facility to export in CSV instead of .xls so that you can view the daa in nan ordinary text editor. Furthermore excel can import CSV files into spreadsheets.

mailx -s "Contains report file $RPTNAME" user@example.com << END
$(uuencode /path/to/devidrpt${RPTNAME}.xls  devidrpt${RPTNAME}.xls)
$(uuencode /ot/path/to/nondevidrpt${RPTNAME}.xls  nondevidrpt${RPTNAME}.xls)
END

                                              
1:
2:
3:
4:

Select allOpen in new window

 

by: rvsBhanuPosted on 2009-07-20 at 07:38:15ID: 24895459

SCRIPT:

#!/bin/csh
RPTNAME="$(date +%b%d%g)"
export RPTNAME
mailx -s "Contains report file $RPTNAME" me@mymail.com << END
$(uuencode /path/to/file/devidrptJul1509${RPTNAME}.xls devidrptJul1509${RPTNAME}.xls)
$(uuencode /path/to /file/nondevidrptJul1509${RPTNAME}.xls nondevidrptJul1509${RPTNAME}.xls)
#
-----------------------------------------------------------------------------------------------------------------------------
Error:
Variable syntax
--------------------------------------------------------------------
Can you pls check this ?Also I would like to know that if the filenames remains fixed,would this work in that scenario also..?If not,can you pls tell me what needs to be done for that ?

 

by: rvsBhanuPosted on 2009-07-20 at 12:06:51ID: 24897936

thx...my script runs fine now after a few modifications.

Though I am still able to open my file, if you could help me with getting the file in excel format with delimiters like space on in place of tab ?Is there any way of acheiving this ?

 

by: rvsBhanuPosted on 2009-08-19 at 10:52:12ID: 25135376

mailx -s "Subject" a@mailaddress.com
******************************************************************************************
Can someone tell me how can I get the subject of the email to be "Report - <todays date>" format ?

 

by: omarfaridPosted on 2009-08-19 at 12:01:51ID: 25136077

try

mailx -s "Subject: `date`" a@mailaddress.com

 

by: omarfaridPosted on 2009-08-19 at 12:02:31ID: 25136081

please note the ` before and after date command

 

by: KeremEPosted on 2009-08-19 at 12:19:07ID: 25136243

Hi

Try this instead. Sorry I've forgot it was CSH for a moment aand used $(..) construct this belongs to bash.

Your Subject has already date in it. Please don't omit the final "END" it is critical.

Cheers,
K.

#!/bin/csh
set RPTNAME="`date +%b%d%g`"
mailx -s "Contains report file $RPTNAME" me@mymail.com << END
`uuencode /path/to/file/devidrptJul1509${RPTNAME}.xls devidrptJul1509${RPTNAME}.xls`
`uuencode /path/to /file/nondevidrptJul1509${RPTNAME}.xls nondevidrptJul1509${RPTNAME}.xls`
END

                                              
1:
2:
3:
4:
5:
6:

Select allOpen in new window

 

by: KeremEPosted on 2009-08-19 at 12:20:16ID: 25136254

RPTMAIL contains Aug1909 as you have requested earlier in the tread...

 

by: rvsBhanuPosted on 2009-09-14 at 21:39:15ID: 31602574

Thank you :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...