We help IT Professionals succeed at work.

How to send a directory of files using SendEmail

IDPInc
IDPInc used Ask the Experts™
on
I'm using the sendemail program to schedule a batch to send a group of daily reports to an outside recipient.  The batch is below:

Set Path=m:\axys351\automatedtrans\insight_nomura

"c:\program files\sendemail\sendemail.exe" -f autoreports@domain.com -t nbrecher@domain.com -u Test -m here are reports from %DATE% a test by neil

brecher -a %path%\abook.abk -s mailserver.domain.com:25 -xu account@domain.com -xp password


While the example above will attach the single file "abook.abk", I would like to set a variable which will attach all of the files in the %path% directory.  So far, %path%\*.*, and %path%\* have yielded no joy. Also leaving the path blank after the %path% variable doesn't work.  The only way to have multiple attachments is to list them specifically with the path.  Which, I guess isn't a big deal, but safer to send everything in the folder listed in the Path variable at the top of the batch file.  

Any ideas?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Hi, you could create a loop, sending each file found in the mentioned directory as a separate mail message. Is this what you want? You could end up sending a lot of mail messages, depending on the amount of files in the directory.

Author

Commented:
I'm not sure I want to go that route.  It's sending to a big $$$ client, and I don't want to annoy them with several emails with the reports.  One is a better solution.  The report output filenames will be known, and I could hard code in the names but if we add reports in the future, I would rather not have the step of editing the batch file.
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
I understand :) Would it be an option to create one zip file with the report files in your directory and send the zip file as one attachment? That way you can write the script once but you have to think about the size of the attachment, how large do you expect it will be? Not every recipient / mail system can handle files of size 50Mb for example...

Author

Commented:
I'd have to script the zipping as well,but I suppose that could work.  Any idea how to script the zip?
Topic Advisor
Most Valuable Expert 2016
Commented:
Here's the basic idea, note that I have 7z.exe (portable) in my path:
rem set variables
set fpath=m:\axys351\automatedtrans\insight_nomura
set ftype=*.abk
set tpath=c:\temp
set repfil=reports.7z

rem delete (existing) zip file (from previous run)
del /s %tpath%\%repfil%

rem create zip file
7z a %tpath%\%repfil% %fpath%\%ftype%

"c:\program files\sendemail\sendemail.exe" -f autoreports@domain.com -t nbrecher@domain.com -u Test -m here are reports from %DATE% a test by neil brecher -a %tpath%\%repfil% -s mailserver.domain.com:25 -xu account@domain.com -xp password

Open in new window

Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
And sample output:

c:\Temp>dir test2
 Volume in drive C is System

 Directory of c:\Temp\test2

04/17/2012  10:53 PM    <DIR>          .
04/17/2012  10:53 PM    <DIR>          ..
04/17/2012  10:19 PM                 7 report.not
04/17/2012  10:19 PM                 7 report1.abk
04/17/2012  10:19 PM                 7 report2.abk
               3 File(s)             21 bytes
               2 Dir(s)  77,369,495,552 bytes free

c:\Temp>zipmail.cmd

c:\Temp>rem set fpath=m:\axys351\automatedtrans\insight_nomura

c:\Temp>rem set ftype=*.abk

c:\Temp>set fpath=c:\temp\test2

c:\Temp>set ftype=*.abk

c:\Temp>set tpath=c:\temp

c:\Temp>set repfil=reports.7z

c:\Temp>del /s c:\temp\reports.7z
Deleted file - c:\temp\reports.7z

c:\Temp>7z a  c:\temp\reports.7z c:\temp\test2\*.abk

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
Scanning

Creating archive c:\temp\reports.7z

Compressing  report1.abk
Compressing  report2.abk

Everything is Ok
c:\program files\sendemail\sendemail.exe -f autoreports@domain.com -t nbrecher@domain.com -u Test -m here are reports from Tue 04/17/2012 a test by neil brecher -a c:\temp\reports.7z -s ...

Open in new window