Emailing with batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Emailing with batch

#1 Post by Notelek_Labs » 23 Jul 2012 07:26

ok, so on my flash drive I have a security system. (at my school the computers don't show hidden files) and the only one not hidden is the in that makes you put in a pass word. if it is wrong, it alerts the user with text and a voice. it also snaps a screenshot and prints all the info in a security log. my question is how to get it to e-Mail me. I wish to do this with att (see below), and it will have to work completely off my flash drive, no port forwards or anything (it will be at school) I am fine with using third party tools as long as it is, like 1 o 2 files and they work! am using at&t for my email, this will let me text my phone!

(as you can tell I am security oriented guy and it would be so cool to make this work)

Requrements:
has to run completely off a flashdrive
has to be fast (before someone could say, close the window)
has to be invisible, like echo hello >nul invisible

I have looked EVERYWHERE and can not find some that meets all this. I hope y'all can help me

thanks
-notelek labs

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Emailing with batch

#2 Post by foxidrive » 23 Jul 2012 07:49

Notelek_Labs wrote:has to be fast (before someone could say, close the window)


When sending an email the program has to log into the server and you are at the mercy of the server as to how long it takes to log in - and then send the email.

So I guess whatever program you use could fail that requirement.

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Emailing with batch

#3 Post by Notelek_Labs » 23 Jul 2012 08:12

by fast i mean like 20-30 seconds if its longer maybe i can shave some time off something else

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Emailing with batch

#4 Post by foxidrive » 23 Jul 2012 08:54

Try this:


Code: Select all

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

:: defaults
set From=me@here.com.au
set To=you@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%
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
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
rem
Last edited by foxidrive on 23 Jul 2012 10:20, edited 1 time in total.

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Emailing with batch

#5 Post by Notelek_Labs » 23 Jul 2012 10:02

nope, it doesn't error, but I don't have an email from it either. Check my Code:

Code: Select all

@echo off
setlocal

:: defaults
set From=me@here.com.au
set To=mfoulks1@gmail.com
set Subj="email test   %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=mfoulks1
set Pass=YEA YOU WISH(Not my real 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%
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Emailing with batch

#6 Post by foxidrive » 23 Jul 2012 10:22

Notelek_Labs wrote:nope, it doesn't error, but I don't have an email from it either. Check my Code:


You can't send from gmail using a non registered email name. You have to use your email address.

Also, add this as the very last line: see my edit above.

rem

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Emailing with batch

#7 Post by Notelek_Labs » 23 Jul 2012 11:24

changed it, but It is Still no working
Code:

Code: Select all

@echo off
setlocal

:: defaults
set From=noteleklabssecuredevices@gmail.com
set To=Nope, not postin it@txt.att.net
set Subj="email test   %date% %time%"
set Body="did it work? %date% %time%"
set Serv=gmail.com
set Auth=noteleklabssecuredevices
set Pass=Not Stupid
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%
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
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
rem

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Emailing with batch

#8 Post by Squashman » 23 Jul 2012 12:05

I believe for gmail your username (auth) needs to be your full email address. Also not sure if you some how you need to specify the PORT for the SMTP server.
If your client does not support SMTP4 authentication, you won't be able to send mail through your client using your Gmail address.

If you're having trouble sending mail but you've confirmed that encryption is active for SMTP in your mail client, try to configure your SMTP server on a different port (465 or 587).

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Emailing with batch

#9 Post by Squashman » 23 Jul 2012 12:16

If you change the SMTPserverport and SSL settings, it should work with Gmail.
http://cybernetnews.com/vbscript-send-e ... ing-gmail/

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Emailing with batch

#10 Post by Liviu » 23 Jul 2012 12:18

@Squashman, you make a good point. Gmail does indeed require (a) the full address for authentication, (b) secure smtp, for example SSL on port 465, and last but not least (c) the account itself to be enabled for POP/SMTP.

@Notelek_Labs, your code has the protocol set to unsecure port 25, which I don't think gmail likes. See the required settings at http://support.google.com/mail/bin/answ ... swer=13287. The other thing you don't mention is how you call the batch file - I'd assume you pass the arguments on the command line, in which case make sure they are quoted as necessary.

Liviu

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: Emailing with batch

#11 Post by Ocalabob » 23 Jul 2012 12:27

Greetings Notelek_Labs,

I do not use Gmail but the script works for me on my ISP.

Try placing a 'PAUSE' in the script to see if that helps
ferret out the error.

For example:

Code: Select all

 call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
PAUSE
del "%vbsfile%" 2>nul
goto :EOF


Good luck!

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Emailing with batch

#12 Post by Notelek_Labs » 23 Jul 2012 12:31

Current code:

Code: Select all

@echo off
setlocal

:: defaults
set From=noteleklabssecuredevices@gmail.com
set To=ASLO CENCORED@txt.att.net
set Subj="email test   %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com:465
set Auth=noteleklabssecuredevices@gmail.com
set Pass=CENCORED
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%
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7 >nul 2>nul
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
rem

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Emailing with batch

#13 Post by Squashman » 23 Jul 2012 12:37

No! Look at the Link I gave you and look at the Code Foxi gave you. You should see where to set the Server Port and SSL settings! Reading is FUN!

Notelek_Labs
Posts: 16
Joined: 22 Jul 2012 20:26

Re: Emailing with batch

#14 Post by Notelek_Labs » 23 Jul 2012 12:44

Ok first off, read my first post. I have scoured google and saw squa's link already and understand simple mail transfer protocol. I just don't get what you are asking about ssl squa.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Emailing with batch

#15 Post by Squashman » 23 Jul 2012 12:53

Notelek_Labs wrote:Ok first off, read my first post. I have scoured google and saw squa's link already and understand simple mail transfer protocol. I just don't get what you are asking about ssl squa.

You realize what the spelling of squa means?

Post Reply