Option to attach different files in Batch

September 9, 2011 at 09:50:21
Specs: Windows 7 Home edition
hello genius pips especially to Ivo. I hope everything is well with you.

Anyways, I would like to ask, is it possible in windows batch file that the program will choose what file to be attached in email. I'm using this code for sending email in batch (courtesy of Ivo)

I would like to achieve this:

Scenario is, the program is testing the content of %file% if it's equal to 0 or not. So

FOR /F "eol= tokens=* delims= usebackq" %%A in (%file%) do (
if "%%A" NEQ "0" (
call :SendEmail
) else (
do some command
call :SendEmail2

SendEmail2 and SendEmail basically have the same content. But I would like them to be separated because of email subject and file attachment. So I would like them to be called if the statement involving them is true.

Can you also tell if the email configuration can be set as a variable so I can make my coding neater? I'm actually using the same configuration in all my programs and I have to declare them on every file. Any response from you guys will be very much appreciated. Thanks as always!

See More: Option to attach different files in Batch

Report •

September 9, 2011 at 10:16:51
Question: Why are you using a batch file to write and call a VBScript? Why not cut out the middle man and go with just VBScript?

How To Ask Questions The Smart Way

Report •

September 9, 2011 at 10:35:06
Hi Razor2.3. Thanks for your response. To answer your question, I still need to run a third party tool which is ideally a combination of batch and vbscript is acceptable. I can only go with batch without vbscript but I don't know how to convert that email configuration to .bat.

If I'm going to use batch only then I think that will make my files lesser and code neater. Can you tell? Thanks!

Report •

September 9, 2011 at 14:55:49
If you want to send email from a batch script, you'll need a third party tool. Blat's the popular choice.

EDIT: Also, I'm suggesting VBScript without batch, not the other way.

How To Ask Questions The Smart Way

Report •

Related Solutions

September 12, 2011 at 10:45:21
Hi Razor. Thanks for the tip! However, I would like to know if the mail configuration and contents like recipient, path/to/files/ can be set as variable? I'm definitely a dumb here and just following examples of other people due to limited knowledge.

still in line with my question above. Maybe you can help me clean and simplify my code here http://pastebin.com/MBaZDew4.

Basically, my code is about taking screenshots on a daily basis from (imacros), compare them. The first call SendEmail will test if the images have different sizes, the second, will just output the difference image using imagemagick.

I just want the code to be clean and use variables as much as possible since it will also be run in another computer. Thanks in advanced.

Report •

Ask Question