Discussion:
Send email via batch file
(too old to reply)
foxidrive
2012-07-13 15:12:50 UTC
Permalink
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=***@here.com.au
set To=***@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
2012-07-13 16:33:09 UTC
Permalink
Post by foxidrive
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
2012-07-14 08:21:38 UTC
Permalink
Post by Timo Salmi
Post by foxidrive
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.

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
2012-07-14 08:26:33 UTC
Permalink
Post by Timo Salmi
Post by Timo Salmi
Post by foxidrive
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.

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
Bob
2012-07-14 15:29:18 UTC
Permalink
Post by foxidrive
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
2012-07-15 20:55:44 UTC
Permalink
Post by Bob
Post by foxidrive
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.
Post by Bob
Best wishes!
And back at'cha!
--
Mic
c***@gmail.com
2012-08-10 11:18:05 UTC
Permalink
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
2012-08-10 16:45:51 UTC
Permalink
Post by c***@gmail.com
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
7Zip is free http://www.7zip.com/
--
Zaidy036
John Gray
2012-08-11 08:39:46 UTC
Permalink
Post by Zaidy036
Post by c***@gmail.com
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
7Zip is free http://www.7zip.com/
--
Zaidy036
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.
k***@gmail.com
2012-12-19 01:33:09 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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
Thanks!!! your a Great HELP!!
Godbless
Tom Lavedas
2012-12-19 15:30:04 UTC
Permalink
Post by foxidrive
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=***@here.com.au
set To=***@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
a***@gmail.com
2013-04-18 08:54:42 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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
j***@gmail.com
2013-08-07 12:22:08 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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
Could this batch file be modified to send to multiple recipients ?
foxidrive
2013-08-07 12:35:32 UTC
Permalink
Post by j***@gmail.com
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
j***@gmail.com
2013-08-07 12:49:46 UTC
Permalink
Post by foxidrive
Post by j***@gmail.com
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
2013-08-07 16:41:22 UTC
Permalink
Post by foxidrive
Post by j***@gmail.com
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.) 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.

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
foxidrive
2013-08-08 02:09:56 UTC
Permalink
Post by Timo Salmi
Post by foxidrive
Post by j***@gmail.com
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
2013-08-10 02:14:15 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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
I don't understand how to use it ?

I see the vbs script that it makes.

Andy
foxidrive
2013-08-10 03:10:40 UTC
Permalink
Post by Andy
Post by foxidrive
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 ***@gmail.com ***@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
2013-08-10 14:59:41 UTC
Permalink
Post by foxidrive
Post by Andy
Post by foxidrive
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.
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
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
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
2013-08-10 15:12:00 UTC
Permalink
Post by foxidrive
Post by foxidrive
Post by Andy
Post by foxidrive
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.
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
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
Foxi,
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = False
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpusessl") = True
when using gmail?
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
2013-08-11 01:29:55 UTC
Permalink
Post by foxidrive
Post by Andy
Post by foxidrive
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.
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
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpserverport") = 25
--
foxi
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
2013-08-11 04:05:31 UTC
Permalink
Post by Andy
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.
Post by Andy
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.
Post by Andy
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.
Post by Andy
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
2013-08-11 13:32:39 UTC
Permalink
Post by foxidrive
Post by Andy
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.
Post by Andy
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.
Post by Andy
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.
Post by Andy
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
Free internet at my apartment complex.

Thanks, I will try you suggestions.

Andy
Andy
2013-08-11 13:59:59 UTC
Permalink
Post by Andy
Post by foxidrive
Post by Andy
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.
Post by Andy
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.
Post by Andy
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.
Post by Andy
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
Free internet at my apartment complex.
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 ???
JJ
2013-08-11 14:39:25 UTC
Permalink
Post by Andy
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.
Andy
2013-08-11 20:00:36 UTC
Permalink
Post by JJ
Post by Andy
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.
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.
Todd Vargo
2013-08-11 20:24:10 UTC
Permalink
Post by Andy
Post by JJ
Post by Andy
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.
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.
Line 18, beginning at the second character.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Andy
2013-08-11 21:50:14 UTC
Permalink
Post by Todd Vargo
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Line 17 end with
Line 18 objEmail.Send
Todd Vargo
2013-08-12 03:02:57 UTC
Permalink
Post by Andy
Line 17 end with
Line 18 objEmail.Send
Were you sending it to a POP account? If not, that explains the message.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Andy
2013-08-12 04:15:38 UTC
Permalink
Post by Todd Vargo
Post by Andy
Line 17 end with
Line 18 objEmail.Send
Were you sending it to a POP account? If not, that explains the message.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
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
Todd Vargo
2013-08-12 10:47:23 UTC
Permalink
Post by Andy
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
(Post questions to group only. Remove "z" to email personal messages)
Andy
2013-08-12 15:51:17 UTC
Permalink
Post by Todd Vargo
Post by Andy
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
(Post questions to group only. Remove "z" to email personal messages)
Are binarys executables or pics ?

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

Andy
Andy
2013-08-12 15:52:59 UTC
Permalink
Post by Todd Vargo
Post by Andy
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
(Post questions to group only. Remove "z" to email personal messages)
Reg. a newsserver. No cc, will look for one who takes debit.

Andy
Andy
2013-08-20 18:51:55 UTC
Permalink
Post by Todd Vargo
Post by Andy
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
foxidrive
2013-08-11 15:01:05 UTC
Permalink
Post by Andy
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 ***@gmail.com ***@gmail.com "This subject is about emails" "This is the body of the email"
smtp.gmail.com ***@gmail.com password "d:\folder\attachment.txt"


***@gmail.com is your email address.
***@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 off
setlocal
:: defaults
set From=***@here.com.au
set To=***@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") = 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
Andy
2013-08-11 20:01:56 UTC
Permalink
Cleaned out by the Todd-o-Cleaner. :-)
foxi
We are making progress.

C:\MASM32\SOURCE\email-bat.vbs(18, 2) CDO.Message.1: The transport failed to con
nect to the server.
Todd Vargo
2013-08-11 17:50:17 UTC
Permalink
Post by Andy
Post by Andy
Post by foxidrive
Post by Andy
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.
Post by Andy
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.
Post by Andy
I don't have a mail server.
Then you are using browser based email not a POP account.
Post by Andy
Post by Andy
Post by foxidrive
The mail server is the one you use to send email from your email client. Your ISP email server for example.
Post by Andy
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.
Post by Andy
Post by Andy
Post by foxidrive
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.
Post by Andy
Post by Andy
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
2013-08-11 19:31:10 UTC
Permalink
Post by Todd Vargo
Post by Andy
Post by Andy
Post by foxidrive
Post by Andy
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.
Post by Andy
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.
Post by Andy
I don't have a mail server.
Then you are using browser based email not a POP account.
Post by Andy
Post by Andy
Post by foxidrive
The mail server is the one you use to send email from your email client. Your ISP email server for example.
Post by Andy
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.
Post by Andy
Post by Andy
Post by foxidrive
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.
Post by Andy
Post by Andy
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)
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
foxidrive
2013-08-11 23:52:20 UTC
Permalink
Post by Andy
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.
Post by Andy
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
Andy
2013-08-12 04:23:15 UTC
Permalink
Post by foxidrive
Post by Andy
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.
Post by Andy
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
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
2013-08-12 04:31:14 UTC
Permalink
Post by Andy
Post by foxidrive
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!
Post by Andy
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
2013-08-12 06:39:04 UTC
Permalink
Post by foxidrive
Post by Andy
Post by foxidrive
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!
Post by Andy
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
Yes, they are an artifact of google groups.

What do you mean ?

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

I feel like a happy guy.
n***@gmail.com
2013-11-14 07:15:25 UTC
Permalink
Hi,,

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

Please help
JJ
2013-11-14 22:22:30 UTC
Permalink
Post by n***@gmail.com
Hi,,
Is there a batch script to know performance monitor & send mail for it?
Please help
Use VBScript and WMI to access the performance service.
b***@gmail.com
2014-02-08 20:28:10 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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
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
2014-02-09 02:59:24 UTC
Permalink
Post by Timo Salmi
foxidrive
code is not working, i try it for sending a from gmail.
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.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 "***@gmail.com"
"***@server.com" "Subject line" "Email Body in one line" "smtp.gmail.com"
"***@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="***@myemailserver.com"
set To="***@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)
del "%vbsfile%" 2>nul
goto :EOF
c***@gmail.com
2014-11-03 21:58:45 UTC
Permalink
Post by foxidrive
Post by Timo Salmi
foxidrive
code is not working, i try it for sending a from gmail.
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.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.
@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 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)
del "%vbsfile%" 2>nul
goto :EOF
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
c***@gmail.com
2014-11-03 22:07:56 UTC
Permalink
Post by c***@gmail.com
Post by foxidrive
Post by Timo Salmi
foxidrive
code is not working, i try it for sending a from gmail.
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.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.
@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 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)
del "%vbsfile%" 2>nul
goto :EOF
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
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 "***@gmail.com"
'email.bat' is not recognized as an internal or external command,
operable program or batch file.

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

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

c:\>"***@gmail.com" "PaigeMichael1" C:\testing.csv"
'"***@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
2014-11-04 03:21:46 UTC
Permalink
Post by c***@gmail.com
C:\Users\Christopher>cd c:\
c:\>EmailTest.bat
What is inside EmailTest.bat ?
Post by c***@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.
Post by c***@gmail.com
operable program or batch file.
Similarly, this error tells you that there is no command called "***@yahoo.com"
p***@gmail.com
2014-08-27 07:41:21 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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
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.....
p***@gmail.com
2014-08-27 07:46:10 UTC
Permalink
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.....
JJ
2014-08-27 15:21:08 UTC
Permalink
Post by p***@gmail.com
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.....
Fishy...
How can it even send the email if your modified code has error?
foxidrive
2014-08-27 09:59:08 UTC
Permalink
Post by p***@gmail.com
Post by foxidrive
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.
p***@gmail.com
2014-08-28 06:00:13 UTC
Permalink
Post by foxidrive
Post by p***@gmail.com
Post by foxidrive
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.
got it.....

thanks...........:)
j***@gmail.com
2015-05-12 20:41:32 UTC
Permalink
what is the Serv!?!??!
and the user is just your email right?
o***@gmail.com
2015-07-08 13:11:09 UTC
Permalink
Post by j***@gmail.com
what is the Serv!?!??!
and the user is just your email right?
This code is useless.
c***@gmail.com
2015-07-21 14:18:43 UTC
Permalink
the cmd is giving error cdo.message . 1: the specified protocol is unknown
r***@gmail.com
2015-08-19 16:05:51 UTC
Permalink
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!
Boris V
2022-06-10 16:10:29 UTC
Permalink
Hello ***@gmail.com,
It is June 2022.
Tweaked your "updated version" for my own needs - works great!

THANK YOU!
Boris V
2022-06-10 16:17:22 UTC
Permalink
"On Wednesday, August 19, 2015 at 5:05:55 PM UTC+1, rm.s..._gmail.com wrote:"

Thank you for the "Updated Version" and advice on how to enable "access for less secure apps".
Tweaked you "Updated Version" to my own needs and it works well.

THANK YOU!!!

a***@premierfoods.co.uk
2018-05-10 10:50:54 UTC
Permalink
Post by foxidrive
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.
@echo off
setlocal
:: defaults
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__
2018-05-10 14:45:59 UTC
Permalink
[snip]
Post by a***@premierfoods.co.uk
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
2018-05-10 20:24:28 UTC
Permalink
Post by a***@premierfoods.co.uk
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
2018-05-17 04:32:32 UTC
Permalink
Post by foxidrive
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.
Loading...