Send email via batch file

22669 views
Skip to first unread message

foxidrive

unread,
Jul 13, 2012, 11:12:50 AM7/13/12
to
This sends an email from the command line/batch file, and it's been proven to work in XP and Win7 so far.

Thanks for the idea and underlying code go to a post from a recent thread here, and a newsgroup post from 2007.

Added is the ability to attach a file, and to use command line arguments or set the arguments from within the batch file.




::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: defaults
set From=m...@here.com.au
set To=y...@lavabit.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=mail.server.com.au
set Auth=user
set Pass=pass
set fileattach=

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

call :createVBS "email-bat.vbs"

call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
echo email has been sent (if parameters were correct)
pause
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7
goto :EOF

:createVBS
set "vbsfile=%~1"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = objArgs(0)
echo >>"%vbsfile%" objEmail.To = objArgs(1)
echo >>"%vbsfile%" objEmail.Subject = objArgs(2)
echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send






--
Mic

Timo Salmi

unread,
Jul 13, 2012, 12:33:09 PM7/13/12
to
On 13.07.2012 18:12 foxidrive wrote:
> This sends an email from the command line/batch file, and it's been
> proven to work in XP and Win7 so far.

Excellent. And I've put together a few lines on the subject as
http://www.netikka.net/tsneti/info/tscmd188.php

All the best, Timo

--
Prof. (emer.) Timo Salmi, Vaasa, Finland
http://www.netikka.net/tsneti/homepage.php
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php

Timo Salmi

unread,
Jul 14, 2012, 4:21:38 AM7/14/12
to
On 13.07.2012 19:33 Timo Salmi wrote:
> On 13.07.2012 18:12 foxidrive wrote:
>> This sends an email from the command line/batch file, and it's been
>> proven to work in XP and Win7 so far.

> Excellent. And I've put together a few lines on the subject as
> http://www.netikka.net/tsneti/info/tscmd188.php

If you have taken a look, foxidrive, you will probably have noticed two
essential additions from me to your solution. The error reporting by the
VBScript and the method to take the body of the message from a file. The
rest is just the ordinary polishing and wrap-up.

Timo Salmi

unread,
Jul 14, 2012, 4:26:33 AM7/14/12
to
On 14.07.2012 11:21 Timo Salmi wrote:
> On 13.07.2012 19:33 Timo Salmi wrote:
>> On 13.07.2012 18:12 foxidrive wrote:
>>> This sends an email from the command line/batch file, and it's been
>>> proven to work in XP and Win7 so far.

>> Excellent. And I've put together a few lines on the subject as
>> http://www.netikka.net/tsneti/info/tscmd188.php

> If you have taken a look, foxidrive, you will probably have noticed two
> essential additions from me to your solution. The error reporting by the
> VBScript and the method to take the body of the message from a file. The
> rest is just the ordinary polishing and wrap-up.

And the inclusion of the x-headers.

Bob

unread,
Jul 14, 2012, 11:29:18 AM7/14/12
to
foxidrive typed the following on 7/13/2012 11:12 AM:
> This sends an email from the command line/batch file, and it's been proven to work in XP and Win7 so far.

Greetings foxidrive,

Nice job putting those lines together! It worked perfect also in my
testing using XP SP3 and Win 7 Home Edition.

Best wishes!

foxidrive

unread,
Jul 15, 2012, 4:55:44 PM7/15/12
to
On Sunday 15/07/2012 01:29, Bob wrote:
> foxidrive typed the following on 7/13/2012 11:12 AM:
>> This sends an email from the command line/batch file, and it's been proven to work in XP and Win7 so far.

> Nice job putting those lines together! It worked perfect also in my
> testing using XP SP3 and Win 7 Home Edition.

And Kudos to Timo and his enhancements.

> Best wishes!

And back at'cha!

--
Mic


checkk...@gmail.com

unread,
Aug 10, 2012, 7:18:05 AM8/10/12
to
My attachment size is larger than what can be sent through our exchange server.
How can we zip the attachment before we sent it through the e-mail.

Any help will be very much appreciated.

thanks in advance

Zaidy036

unread,
Aug 10, 2012, 12:45:51 PM8/10/12
to
7Zip is free http://www.7zip.com/

--
Zaidy036

John Gray

unread,
Aug 11, 2012, 4:39:46 AM8/11/12
to
So is right-clicking on the file in Windows Explorer or in My Computer, and choosing "Send to" then "Compressed (zipped) folder".
In fact, this produces a file, not a folder, but Microsoft always seems to have been confused about ZIP(ped) files.

kirahm...@gmail.com

unread,
Dec 18, 2012, 8:33:09 PM12/18/12
to
Thanks!!! your a Great HELP!!
Godbless

Tom Lavedas

unread,
Dec 19, 2012, 10:30:04 AM12/19/12
to
On Friday, July 13, 2012 11:12:50 AM UTC-4, foxidrive wrote:
> This sends an email from the command line/batch file, and it's been
> proven to work in XP and Win7 so far.

I've tried to build a version that eliminates the temporary script file with an approach I developed that uses mshta.exe as the host instead of cscript. I've checked the syntax, but am unable to test the actual email functionality because of my company's internet security settings. It doesn't allow access to external SMTP servers. So, I offer this version with the caveat that it is, as yet, unproven ...

:: email-bat.cmd ::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Modified to eliminate temporary VBS script file
@echo off
setlocal

:: defaults
set From=m...@here.com.au
set To=y...@lavabit.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=mail.server.com.au
set Auth=user
set Pass=pass
set fileattach=

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

set "VBS=with createobject(""scripting.filesystemobject""):"
set "VBS=%VBS%Execute(.GetStandardStream(0).readALL):"
set "VBS=%VBS%:end with:close"

call :send %1 %2 %3 %4 %5 %6 %7

echo email has been sent (if parameters were correct)
pause
goto :EOF

:send
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
if defined fileattach (
set "FA=echo objEmail.AddAttachment "%fileattach%""
) else (
set "FA="
)
(
echo Set objEmail = CreateObject("CDO.Message"^^^)
echo objEmail.From = "%~1"
echo objEmail.To = "%~2"
echo objEmail.Subject = "%~3"
echo objEmail.Textbody = "%~4"
%FA%
echo with objEmail.Configuration.Fields
echo .Item ("%cdoSchema%/sendusing"^^^) = 2 ' not local, smtp
echo .Item ("%cdoSchema%/smtpserver"^^^) = "%~5"
echo .Item ("%cdoSchema%/smtpserverport"^^^) = 25
echo .Item ("%cdoSchema%/smtpauthenticate"^^^) = 1 ' cdobasic
echo .Item ("%cdoSchema%/sendusername"^^^) = "%~6"
echo .Item ("%cdoSchema%/sendpassword"^^^) = "%~7"
echo .Item ("%cdoSchema%/smtpusessl"^^^) = False
echo .Item ("%cdoSchema%/smtpconnectiontimeout"^^^) = 25
echo .Update
echo end with
echo objEmail.Send
) | mshta.exe vbscript:Execute("%VBS%")

It also lacks the added features that Timo provided.
______________________________
Tom Lavedas

ansh...@gmail.com

unread,
Apr 18, 2013, 4:54:42 AM4/18/13
to

jjbk...@gmail.com

unread,
Aug 7, 2013, 8:22:08 AM8/7/13
to
Could this batch file be modified to send to multiple recipients ?

foxidrive

unread,
Aug 7, 2013, 8:35:32 AM8/7/13
to
On 7/08/2013 22:22, jjbk...@gmail.com wrote:
> Could this batch file be modified to send to multiple recipients ?

Yes, you can use another batch file to call the email send one, with all the details as parameters.

--
foxi

jjbk...@gmail.com

unread,
Aug 7, 2013, 8:49:46 AM8/7/13
to
On Wednesday, August 7, 2013 1:35:32 PM UTC+1, foxidrive wrote:
> On 7/08/2013 22:22, jjbk....@gmail.com wrote:
>
> > Could this batch file be modified to send to multiple recipients ?
>
>
>
> Yes, you can use another batch file to call the email send one, with all the details as parameters.
>
>
>
> --
>
> foxi

Thanks for the prompt reply however I do not fully understand. Can you give me an example or explain further please?
Thanks
jjb

Timo Salmi

unread,
Aug 7, 2013, 12:41:22 PM8/7/13
to
That's different, if I understand your suggestion correctly. What the
recipient(s) will see in the headers will differ. Depending on the
circumstances it may be important to see who else has been on the
recipient list. (Besides, how to send group replies, if the messages are
factually separate.) I do not have a direct answer to the original
question, but I think the answer is yes. Because that's exactly what I
do with the rekindled FAQ pointer posting. Only one posting, one script,
to cover both the "recipient" newsgroups.

foxidrive

unread,
Aug 7, 2013, 10:09:56 PM8/7/13
to
On 8/08/2013 02:41, Timo Salmi wrote:
> On 07.08.2013 15:35 foxidrive wrote:
>> On 7/08/2013 22:22, jjbk...@gmail.com wrote:
>>> Could this batch file be modified to send to multiple recipients ?
>>
>> Yes, you can use another batch file to call the email send one, with
>> all the details as parameters.
>
> That's different, if I understand your suggestion correctly. What the
> recipient(s) will see in the headers will differ. Depending on the
> circumstances it may be important to see who else has been on the
> recipient list. (Besides, how to send group replies, if the messages are
> factually separate.)

That's a good point.

I wonder if the poster has a legit reason to use it, or a spammish reason.


--
foxi

Andy

unread,
Aug 9, 2013, 10:14:15 PM8/9/13
to
> Mic

I don't understand how to use it ?

I see the vbs script that it makes.

Andy

foxidrive

unread,
Aug 9, 2013, 11:10:40 PM8/9/13
to
On 10/08/2013 12:14, Andy wrote:
> On Friday, July 13, 2012 10:12:50 AM UTC-5, foxidrive wrote:
>> This sends an email from the command line/batch file, and it's been proven to work in XP and Win7 so far.

> I don't understand how to use it ?
>
> I see the vbs script that it makes.

This should be on one line.

email.bat m...@gmail.com y...@hotmail.com "This subject is about emails" "This is the body of the email"
smtp.gmail.com username password "c:\folder\file.txt"



To use SSL that gmail requires while sending email, use this line

echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 465

instead of this:

echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25


--
foxi

Bob

unread,
Aug 10, 2013, 10:59:41 AM8/10/13
to
Foxi,
In addition, didn't this line:
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False

need to be changed to:
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = True

when using gmail?


foxidrive

unread,
Aug 10, 2013, 11:12:00 AM8/10/13
to
I do believe you have spotted my cunning intentional omission. ;) 10 out of 10 for eagle-eye-ness.


Thanks for the correction, Bob.


--
foxi

Andy

unread,
Aug 10, 2013, 9:29:55 PM8/10/13
to
I am getting a vbscript runtime error subscript out of range.

But I am sending from yahoo.com so it may not work.

I don't have a mail server.

I am using wireless internet from an open network, so it may not work ?

Andy

foxidrive

unread,
Aug 11, 2013, 12:05:31 AM8/11/13
to
On 11/08/2013 11:29, Andy wrote:

> I am getting a vbscript runtime error subscript out of range.

Copy and paste the original again, and then modify it again. Take note of Bob's correction.

> But I am sending from yahoo.com so it may not work.

yahoo.com in some locations doesn't allow sending from an email client, but check the above first.

> I don't have a mail server.

The mail server is the one you use to send email from your email client. Your ISP email server for example.

> I am using wireless internet from an open network, so it may not work ?

You mean you are piggy backing off a free network? Get a gmail account and enable pop access and then
try it with that.



--
foxi

Andy

unread,
Aug 11, 2013, 9:32:39 AM8/11/13
to
> foxi

Free internet at my apartment complex.

Thanks, I will try you suggestions.

Andy

Andy

unread,
Aug 11, 2013, 9:59:59 AM8/11/13
to

JJ

unread,
Aug 11, 2013, 10:39:25 AM8/11/13
to
On Sun, 11 Aug 2013 06:59:59 -0700 (PDT), Andy wrote:
> Did everything but still getting same error.
>
> http://classicasp.aspfaq.com/general/why-am-i-getting-subscript-out-of-range-errors.html ???

Make sure you specify parameter #1 to #7 of the batch file.

The VBS error message tells you the exact line number (in the VBS file)
where the error occured. That'll tell you which VBS parameter is missing.

foxidrive

unread,
Aug 11, 2013, 11:01:05 AM8/11/13
to
On 11/08/2013 23:59, Andy wrote:

> Did everything but still getting same error.

Try this batch file - it has been tested with gmail and uses SSL and port 465 to send.

Execute the command as follows, but this command is all on one line.

email.bat bi...@gmail.com s...@gmail.com "This subject is about emails" "This is the body of the email"
smtp.gmail.com bi...@gmail.com password "d:\folder\attachment.txt"


bi...@gmail.com is your email address.
s...@gmail.com is the recipient email address.
"d:\folder\attachment.txt" is the attachment to send.

Re-read Timo's list of batch material as he has some enhancements, and there are other versions of this
after mine, that don't require a temp file.


::email.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 465
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = True
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
:end



--
foxi

Todd Vargo

unread,
Aug 11, 2013, 1:50:17 PM8/11/13
to
On 8/11/2013 9:59 AM, Andy wrote:
> On Sunday, August 11, 2013 8:32:39 AM UTC-5, Andy wrote:
>> On Saturday, August 10, 2013 11:05:31 PM UTC-5, foxidrive wrote:
>>
>>> On 11/08/2013 11:29, Andy wrote:
>>
>>
>>
>>>
>>
>>>> I am getting a vbscript runtime error subscript out of range.
>>
>>
>>
>>> Copy and paste the original again, and then modify it again. Take note of Bob's correction.
>>
>>>
>>
>>>
>>
>>>
>>
>>>> But I am sending from yahoo.com so it may not work.
>>
>>>
>>
>>>
>>
>>>
>>
>>> yahoo.com in some locations doesn't allow sending from an email client, but check the above first.
>>
>>>
>>
>>>
>>
>>>
>>
>>>> I don't have a mail server.

Then you are using browser based email not a POP account.

>>
>>>
>>
>>>
>>
>>>
>>
>>> The mail server is the one you use to send email from your email client. Your ISP email server for example.
>>
>>>
>>
>>>
>>
>>>
>>
>>>> I am using wireless internet from an open network, so it may not work ?

In other words, you do not have a POP account with yahoo so you are
exactly correct, the batch will not work for you.

>>
>>
>>
>>> You mean you are piggy backing off a free network? Get a gmail account and enable pop access and then
>>
>>>
>>
>>> try it with that.
>>
>>>
>>
>>
>>
>>> foxi
>>
>>
>>
>> Free internet at my apartment complex.

Free internet is irrelevant to the matter at hand. You need a POP account.

>>
>>
>>
>> Thanks, I will try you suggestions.
>>
>>
>>
>> Andy
>
> Did everything but still getting same error.
>
> http://classicasp.aspfaq.com/general/why-am-i-getting-subscript-out-of-range-errors.html ???

What does "did everything" mean? If you don't say it, then we don't know
what exactly was tried, what may have been omitted, or typed/pasted wrong.

On a side note, the added spacing on each reply is terribly annoying.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Andy

unread,
Aug 11, 2013, 3:31:10 PM8/11/13
to
Sorry about the spacing, it's yahoo's fault.

I tried to setup a newsreader but none of the free host sites worked with it.

Andy

Andy

unread,
Aug 11, 2013, 4:00:36 PM8/11/13
to
Which line it ? 18 or 2 or both ?

Andy

C:\MASM32\SOURCE\email-bat.vbs(18, 2) CDO.Message.1: The transport failed to con
nect to the server.

Andy

unread,
Aug 11, 2013, 4:01:56 PM8/11/13
to
On Sunday, August 11, 2013 10:01:05 AM UTC-5, foxidrive wrote:
> On 11/08/2013 23:59, Andy wrote:

Cleaned out by the Todd-o-Cleaner. :-)

> foxi

We are making progress.

Todd Vargo

unread,
Aug 11, 2013, 4:24:10 PM8/11/13
to
Line 18, beginning at the second character.

Andy

unread,
Aug 11, 2013, 5:50:14 PM8/11/13
to
Line 17 end with
Line 18 objEmail.Send

foxidrive

unread,
Aug 11, 2013, 7:52:20 PM8/11/13
to
On 12/08/2013 05:31, Andy wrote:
> Sorry about the spacing, it's yahoo's fault.

It's Google's fault. You're using google groups.
It's a shame that google cant get it right, after so long.

> I tried to setup a newsreader but none of the free host sites worked with it.

Andy, you could do worse than to set up a free account here for 50 MB a day.

http://www.teranews.com

It does require a credit card spend of $4 to set up the account but it never requires you to spend any
more. I've been using the free account forever.



--
foxi

Todd Vargo

unread,
Aug 11, 2013, 11:02:57 PM8/11/13
to
On 8/11/2013 5:50 PM, Andy wrote:
>
> Line 17 end with
> Line 18 objEmail.Send
>

Were you sending it to a POP account? If not, that explains the message.

--

Andy

unread,
Aug 12, 2013, 12:15:38 AM8/12/13
to
Todd,

Thanks for your patience and help.

How would I determine that ?

Andy

I will go with foxi's suggestion.

This group drives me crazy with some of their posters "kiddy ville" bickering.

They have a lot of good information.

alt.comp.freeware

Andy

unread,
Aug 12, 2013, 12:23:15 AM8/12/13
to
> foxi

New Unlimited Packages: We now offer unlimited accounts for $12/month (6 month plan) or $14.95

Foxi,

Thanks.

I am seriously thinking about it.

I am retired and on a fixed income.

I am guessing I have more options like filtering out Tedd (Joke for my good friend Tedd).

Will it get rid of the double spacing and retarded empty lines ? :-)

Andy

foxidrive

unread,
Aug 12, 2013, 12:31:14 AM8/12/13
to
On 12/08/2013 14:23, Andy wrote:
> On Sunday, August 11, 2013 6:52:20 PM UTC-5, foxidrive wrote:
>> Andy, you could do worse than to set up a free account here for 50 MB a day.
>>
>> http://www.teranews.com
>>
>> It does require a credit card spend of $4 to set up the account but it never requires you to spend any
>> more. I've been using the free account forever.
>
> New Unlimited Packages: We now offer unlimited accounts for $12/month (6 month plan) or $14.95

If you use binaries then that might be attractive, but for text groups the 50 MB a day is scads more than
you can read in 24 hours!

> I am guessing I have more options like filtering out Tedd (Joke for my good friend Tedd).
> Will it get rid of the double spacing and retarded empty lines ? :-)

Yes, they are an artifact of google groups.

Use Thunderbird for a free usenet client, or another one if you prefer. All the filtering is in that.


--
foxi

Andy

unread,
Aug 12, 2013, 2:39:04 AM8/12/13
to
What do you mean ?

I think of artifacts as bones of dinosaus, like T-Rex. :_)

I feel like a happy guy.


Todd Vargo

unread,
Aug 12, 2013, 6:47:23 AM8/12/13
to
On 8/12/2013 12:15 AM, Andy wrote:
>
> Todd,
>
> Thanks for your patience and help.
>
> How would I determine that ?
>
> Andy
>
> I will go with foxi's suggestion.
>
> This group drives me crazy with some of their posters "kiddy ville" bickering.
>
> They have a lot of good information.
>
> alt.comp.freeware

Andy, the best part is you wont have to keep downloading entire threads
over and over. Just set whatever news client you choose to retain
messages longer than its default setting. You want to see some
bickering? Post binaries to a text group and you'll soon see who the
dialup users are. :)

Andy

unread,
Aug 12, 2013, 11:51:17 AM8/12/13
to
Are binarys executables or pics ?

If so does it make dialup users made because of the large file sizes ?

Andy

Andy

unread,
Aug 12, 2013, 11:52:59 AM8/12/13
to
On Monday, August 12, 2013 5:47:23 AM UTC-5, Todd Vargo wrote:
Reg. a newsserver. No cc, will look for one who takes debit.

Andy

Andy

unread,
Aug 20, 2013, 2:51:55 PM8/20/13
to
On Monday, August 12, 2013 10:52:59 AM UTC-5, Andy wrote:
> On Monday, August 12, 2013 5:47:23 AM UTC-5, Todd Vargo wrote:
>
> > On 8/12/2013 12:15 AM, Andy wrote:
>
> >
>
> > >
>
> >
>
> > > Todd,
>
> >
>
> > >
>
> >
>
> > > Thanks for your patience and help.
>
> >
>
> > >
>
> >
>
> > > How would I determine that ?
>
> >
>
> > >
>
> >
>
> > > Andy
>
> >
>
> > >
>
> >
>
> > > I will go with foxi's suggestion.
>
> >
>
> > >
>
> >
>
> > > This group drives me crazy with some of their posters "kiddy ville" bickering.
>
> >
>
> > >
>
> >
>
> > > They have a lot of good information.
>
> >
>
> > >
>
> >
>
> > > alt.comp.freeware
>
> >
>
> >
>
> >
>
> > Andy, the best part is you wont have to keep downloading entire threads
>
> >
>
> > over and over. Just set whatever news client you choose to retain
>
> >
>
> > messages longer than its default setting. You want to see some
>
> >
>
> > bickering? Post binaries to a text group and you'll soon see who the
>
> >
>
> > dialup users are. :)
>
> >
>
> >
>
> >
>
> > --
>
> >
>
> > Todd Vargo
>

> Andy

I would like to help and find out why the program isn't working for me.

I have XP Pro Sp3.

Andy

niti...@gmail.com

unread,
Nov 14, 2013, 2:15:25 AM11/14/13
to
Hi,,

Is there a batch script to know performance monitor & send mail for it?

Please help

JJ

unread,
Nov 14, 2013, 5:22:30 PM11/14/13
to
Use VBScript and WMI to access the performance service.

blackp...@gmail.com

unread,
Feb 8, 2014, 3:28:10 PM2/8/14
to
On Friday, July 13, 2012 8:12:50 AM UTC-7, foxidrive wrote:
> This sends an email from the command line/batch file, and it's been proven to work in XP and Win7 so far.
>
>
>
> Thanks for the idea and underlying code go to a post from a recent thread here, and a newsgroup post from 2007.
>
>
>
> Added is the ability to attach a file, and to use command line arguments or set the arguments from within the batch file.
>
>
>
>
>
>
>
>
>
> ::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
>
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
>
> echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
>
> echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
>
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False
>
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
>
> echo >>"%vbsfile%" .Update
>
> echo >>"%vbsfile%" end with
>
> echo >>"%vbsfile%" objEmail.Send
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
>
> Mic

foxidrive
code is not working, i try it for sending a from gmail.

set From=x*******@gmail.com
set To=y*******@gmail.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=x******@gmail.com
set Pass=********
set fileattach=

please help me...

foxidrive

unread,
Feb 8, 2014, 9:59:24 PM2/8/14
to
On 9/02/2014 07:28, blackp...@gmail.com wrote:

> foxidrive
> code is not working, i try it for sending a from gmail.
>
> set From=x*******@gmail.com
> set To=y*******@gmail.com
> set Subj="email test %date% %time%"
> set Body="did it work? %date% %time%"
> set Serv=smtp.gmail.com
> set Auth=x******@gmail.com
> set Pass=********
> set fileattach=
>
> please help me...

This one may be easier to use. Gmail needs the SSL and port changed so read the comments at the start.


:: for the command line use this format: CALL email.bat "myn...@gmail.com"
"RecipientE...@server.com" "Subject line" "Email Body in one line" "smtp.gmail.com"
"myn...@gmail.com" "password" "d:\folder\filename to attach.txt"


:: email.bat :::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: use these settings to send from a gmail account
:: set port=465 and set SSL=True

:: use these settings for standard email SMTP port and no encryption
:: set port=25 and set SSL=False

:: Change these following items to use the same variables all the time
:: or use the command line to pass all the variables

set Port=25
set SSL=False
set From="mye...@myemailserver.com"
set To="reci...@server.com"
set Subject="Subject line"
set Body="Email Body in one line"
set SMTPServer="mailservername.myemailserver.com"
set User="username"
set Pass="password"
set fileattach="d:\myfolder\file.txt"


:: This section sets the command line arguments


if "%~7" NEQ "" (
set From="%~1"
set To="%~2"
set Subject="%~3"
set Body="%~4"
set SMTPServer="%~5"
set User="%~6"
set Pass="%~7"
set fileattach="%~8"
)

set "vbsfile=%temp%\email-bat.vbs"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = %From%
echo >>"%vbsfile%" objEmail.To = %To%
echo >>"%vbsfile%" objEmail.Subject = %Subject%
echo >>"%vbsfile%" objEmail.Textbody = %body%
if exist %fileattach% echo >>"%vbsfile%" objEmail.AddAttachment %fileattach%
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = %SMTPServer%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = %port%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = %user%
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = %pass%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = %SSL%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 30
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send

cscript.exe /nologo "%vbsfile%"
echo email sent (if variables were correct)
Message has been deleted

pasa...@gmail.com

unread,
Aug 27, 2014, 3:46:10 AM8/27/14
to
how to send multiple attachments with this code, i tried to modify but got error, "email-bat.vbs <9 , 2> CDO.Message.1" only two attachments are send but i need to send 5... Plz post the solution.....

foxidrive

unread,
Aug 27, 2014, 5:59:08 AM8/27/14
to
On 27/08/2014 17:41, pasa...@gmail.com wrote:
> On Friday, 13 July 2012 20:12:50 UTC+5, foxidrive wrote:
>> This sends an email from the command line/batch file, and it's been proven to work in XP and
>> Win7 so far.
>>
>>
>
>
> how to send multiple attachments with this cose, i mtry to modified but got error, "email-bat.vbs
> 9 , 2> CDO.Message.1" only two attachments are send but i need to send 5... Plz post the
> solution.....
>

Zip up the 5 files into one attachment.

JJ

unread,
Aug 27, 2014, 11:21:08 AM8/27/14
to
Fishy...
How can it even send the email if your modified code has error?

pasa...@gmail.com

unread,
Aug 28, 2014, 2:00:13 AM8/28/14
to
got it.....

thanks...........:)

che...@gmail.com

unread,
Nov 3, 2014, 4:58:47 PM11/3/14
to
This isnt working for me...

Can someone help?

Not sure why tech people only post the code but dont give instructions on how to get it working...

Thanks

che...@gmail.com

unread,
Nov 3, 2014, 5:07:58 PM11/3/14
to
This is what I get when I run this:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\Christopher>cd c:\

c:\>EmailTest.bat

c:\>CALL email.bat "che...@gmail.com"
'email.bat' is not recognized as an internal or external command,
operable program or batch file.

c:\>"che...@yahoo.com" "Subject line" "Email Body in one line" "smtp.gmail.com"

'"che...@yahoo.com"' is not recognized as an internal or external command,
operable program or batch file.

c:\>"che...@gmail.com" "PaigeMichael1" C:\testing.csv"
'"che...@gmail.com"' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\CHRIST~1\AppData\Local\Temp\email-bat.vbs(19, 2) CDO.Message.1: The "Se
ndUsing" configuration value is invalid.


email sent (if variables were correct)

Can anyone help?

foxidrive

unread,
Nov 3, 2014, 10:21:48 PM11/3/14
to
On 4/11/2014 09:07, che...@gmail.com wrote:
> C:\Users\Christopher>cd c:\
>
> c:\>EmailTest.bat

What is inside EmailTest.bat ?


> c:\>CALL email.bat "che...@gmail.com"
> 'email.bat' is not recognized as an internal or external command,
> operable program or batch file.

This error tells you that you do not have an email.bat available.


> c:\>"che...@yahoo.com" "Subject line" "Email Body in one line" "smtp.gmail.com"
>
> '"che...@yahoo.com"' is not recognized as an internal or external command,
> operable program or batch file.

Similarly, this error tells you that there is no command called "che...@yahoo.com"



jlell...@gmail.com

unread,
May 12, 2015, 4:41:34 PM5/12/15
to


what is the Serv!?!??!
and the user is just your email right?

ozca...@gmail.com

unread,
Jul 8, 2015, 9:11:10 AM7/8/15
to
On Tuesday, May 12, 2015 at 11:41:34 PM UTC+3, jlell...@gmail.com wrote:
> what is the Serv!?!??!
> and the user is just your email right?

This code is useless.

chawlaa...@gmail.com

unread,
Jul 21, 2015, 10:18:44 AM7/21/15
to
the cmd is giving error cdo.message . 1: the specified protocol is unknown

rm.s...@gmail.com

unread,
Aug 19, 2015, 12:05:55 PM8/19/15
to
Thanks for the awesome code!

Here's a slightly modified version I made, which grabs the newest file in a specified folder and emails it.


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Original code found at https://groups.google.com/forum/#!topic/alt.msdos.batch.nt/lJS06Bs4iWE see post dated 08/02/2014 by foxidrive

:: First login to the gmail account and go to this page
:: https://www.google.com/settings/security/lesssecureapps turn on access for less secure apps


::email-bat.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::: Begin Original code


@echo off
setlocal

:: use these settings to send from a gmail account
:: set port=465 and set SSL=True

:: Change these following items to use the same variables all the time
:: or use the command line to pass all the variables


::Set the filepath here- finds the newest file in the specified folder
@cd C:\myfolderpath
for /f %%i in ('dir /b /s /a-d/od/t:c') do set LAST=%%i
::echo The most recently created file is %LAST%


::varibles must be in quotations
set Port=465
set SSL=TRUE
set From="m****@gmail.com"
set To="y*****@@blank.com"
set Subject="Test email"
set Body="Email Body in one line"
set SMTPServer= "smtp.gmail.com"
set User="m*****@gmail.com"
set Pass="passwordhere"
set fileattach="%LAST%"

set "vbsfile=%temp%\email-bat.vbs"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
@echo >>"%vbsfile%" Set objArgs = WScript.Arguments
echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From = %From%
echo >>"%vbsfile%" objEmail.To = %To%
echo >>"%vbsfile%" objEmail.Subject = %Subject%
echo >>"%vbsfile%" objEmail.Textbody = %body%
if exist %fileattach% echo >>"%vbsfile%" objEmail.AddAttachment %fileattach%
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = %SMTPServer%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = %port%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = %user%
echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = %pass%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = %SSL%
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 30
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
cscript.exe /nologo %vbsfile%


echo email sent (if variables were correct)

::email-bat.cmd::::::::::::::::::::::::::::::: End Original code
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Hope this helps someone as much as it helped me!

andy.e...@premierfoods.co.uk

unread,
May 10, 2018, 6:50:55 AM5/10/18
to
On Friday, 13 July 2012 16:12:50 UTC+1, foxidrive wrote:
> This sends an email from the command line/batch file, and it's been proven to work in XP and Win7 so far.
>
> Thanks for the idea and underlying code go to a post from a recent thread here, and a newsgroup post from 2007.
>
> Added is the ability to attach a file, and to use command line arguments or set the arguments from within the batch file.
>
>
>
>
> ::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
> @echo off
> setlocal
>
> :: defaults
> set From=m...@here.com.au
> set To=y...@lavabit.com
> set Subj="email test %date% %time%"
> set Body="did it work? %date% %time%"
> set Serv=mail.server.com.au
> set Auth=user
> set Pass=pass
> set fileattach=
>
> :: if command line arguments are supplied then use them
> if "%~7" NEQ "" (
> set From=%1
> set To=%2
> set Subj="%~3"
> set Body="%~4"
> set Serv=%5
> set "Auth=%~6"
> set "Pass=%~7"
> set "fileattach=%~8"
> )
>
> call :createVBS "email-bat.vbs"
>
> call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
> echo email has been sent (if parameters were correct)
> pause
> del "%vbsfile%" 2>nul
> goto :EOF
>
> :send
> cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7
> goto :EOF
>
> :createVBS
> set "vbsfile=%~1"
> del "%vbsfile%" 2>nul
> set cdoSchema=http://schemas.microsoft.com/cdo/configuration
> echo >>"%vbsfile%" Set objArgs = WScript.Arguments
> echo >>"%vbsfile%" Set objEmail = CreateObject("CDO.Message")
> echo >>"%vbsfile%" objEmail.From = objArgs(0)
> echo >>"%vbsfile%" objEmail.To = objArgs(1)
> echo >>"%vbsfile%" objEmail.Subject = objArgs(2)
> echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
> if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
> echo >>"%vbsfile%" with objEmail.Configuration.Fields
> echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserver") = objArgs(4)
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
> echo >>"%vbsfile%" .Item ("%cdoSchema%/sendusername") = objArgs(5)
> echo >>"%vbsfile%" .Item ("%cdoSchema%/sendpassword") = objArgs(6)
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False
> echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
> echo >>"%vbsfile%" .Update
> echo >>"%vbsfile%" end with
> echo >>"%vbsfile%" objEmail.Send
>
>
>
>
>
>
> --
> Mic

Hi,

I maybe missing something here, tryring to test your lovely batch file script, but getting a message when I run it stating
"email-bat.vbs(7, 2) CDO.Message.1: The specified protocol is unknown

what have I not done correctly?

thanks
andy

--
****************************************************************************************** 

Any opinions expressed in this email are those of the individual and not
necessarily of Premier Foods plc and/or any of its subsidiaries. 


This
email and any files transmitted with it are private, may be confidential
and are for the intended recipient only. If you are not the intended
recipient, be advised that you have received them in error.  Please notify
the sender of the error, delete all copies of them from your system and
destroy any printed copies.


If you are not the intended recipient, you
are not authorized to read, print, retain, copy, disseminate, distribute,
or use this email and any files transmitted with it.


Please rely on your
own anti-virus system.  No responsibility is taken by Premier Foods plc
and/or any of its subsidiaries for any damage arising out of any bug or
virus infection.


Premier Foods Group Ltd No. 281728 and Premier Foods
Group Services Ltd No. 3977318 are trading companies of Premier Foods plc
No. 5160050. All registered in England with Registered Office: Premier
House, Centrium Business Park, Griffiths Way, St Albans AL1 2RE.

******************************************************************************************

Auric__

unread,
May 10, 2018, 10:46:00 AM5/10/18
to
andy.ellison wrote:

> On Friday, 13 July 2012 16:12:50 UTC+1, foxidrive wrote:
[snip]
> I maybe missing something here, tryring to test your lovely batch file
> script, but getting a message when I run it stating "email-bat.vbs(7, 2)
> CDO.Message.1: The specified protocol is unknown
>
> what have I not done correctly?

Well, let's see...

1) Didn't say what OS.
2) Didn't mention what changes were made to the batch file, if any.
3) Replied to a 6-year-old post.

...with the added bonus that foxidrive died a year and a half ago.

--
My attention span will focus on monkeys in 45 seconds.

JJ

unread,
May 10, 2018, 4:24:29 PM5/10/18
to
On Thu, 10 May 2018 03:50:54 -0700 (PDT), andy.e...@premierfoods.co.uk
wrote:
>
> I maybe missing something here, tryring to test your lovely batch file script, but getting a message when I run it stating
> "email-bat.vbs(7, 2) CDO.Message.1: The specified protocol is unknown
>
> what have I not done correctly?
>
> thanks
> andy

Full path must be used.

Tom Del Rosso

unread,
May 17, 2018, 12:32:35 AM5/17/18
to
andy.e...@premierfoods.co.uk wrote:
> On Friday, 13 July 2012 16:12:50 UTC+1, foxidrive wrote:
>> This sends an email from the command line/batch file, and it's been
>> proven to work in XP and Win7 so far.

I never tried that one, but BLAT.EXE is easy to use and works well.



Message has been deleted

Boris V

unread,
Jun 10, 2022, 12:17:24 PMJun 10