Emailing with batch
Moderator: DosItHelp
-
- Posts: 16
- Joined: 22 Jul 2012 20:26
Re: Emailing with batch
not really, just refering to your username
EDIT: Oh god, just googled it. Didn't mean that, its just the first four letters of your username. sorry if that was offensive
EDIT: Oh god, just googled it. Didn't mean that, its just the first four letters of your username. sorry if that was offensive
Re: Emailing with batch
Notelek_Labs wrote:Ok first off, read my first post.
No, first off, you please read the replies

Liviu
-
- Posts: 16
- Joined: 22 Jul 2012 20:26
Re: Emailing with batch
Current code:
Code: Select all
@echo off
setlocal
:: defaults
set From=noteleklabssecuredevices@gmail.com
set To=**********@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=*******
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%
pause
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") = True
echo >>"%vbsfile%" .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
rem
Re: Emailing with batch
No, that's still not right. Remove ":465" from the "Serv=" line. Do this, instead.
Liviu wrote:change smtpserverport from 25 to 465
Re: Emailing with batch
It works for me using the code as I posted and this format - my gmail account is also enabled for pop/smtp
Code: Select all
:: defaults
set From=peterpumpkineater@gmail.com
set To=arial@lavabit.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=peterpumpkineater
set Pass=password
set fileattach=
Re: Emailing with batch
foxidrive wrote:It works for me using the code as I posted and this format
Interesting. I just rechecked using my gmail accounts, and:
- can't send over port 25 regardless of the SSL setting (FWIW there is a gmail advice to try 25 SSL as a last resort at http://support.google.com/mail/bin/answ ... swer=78775 under "still can't send"); I know for a fact that I don't have port 25 blocked by my ISP (some do) since other email accounts using it work fine;
- can send using 465 SSL, with either the full @gmail address or just the username part of it for authentication.
I can only guess that gmail, like others, might have different rules for different addresses grandfathered-in.
That said, I'd still recommend the official settings from http://support.google.com/mail/bin/answ ... swer=13287 - full address and 465 SSL.
Liviu
Re: Emailing with batch
This works with SSL and port 465
Code: Select all
::email-SSL-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: defaults
set From=put_your_gmail_name_here@gmail.com
set To=receiver@lavabit.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=put_your_gmail_name_here
set Pass=put_your_gmail_password_here
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 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") = 30
echo >>"%vbsfile%" .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
rem
-
- Posts: 16
- Joined: 22 Jul 2012 20:26
Re: Emailing with batch
WOOOOOOOOOOOOOO finally! I got it working
! Thanks for the help
Working Code:
! Thanks for the help
Working Code:
Code: Select all
@echo off
setlocal
:: defaults
set From=noteleklabssecuredevices@gmail.com
set To=asdfjkl;@txt.att.net
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=smtp.gmail.com
set Auth=noteleklabssecuredevices@gmail.com
set Pass=asdfjkl;
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%
pause
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") = 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
rem
Re: Emailing with batch
Notelek_Labs wrote:WOOOOOOOOOOOOOO finally! I got it working
! Thanks for the help
Working Code:
Do you actually understand the SMTP settings now that create the VBscript?
Re: Emailing with batch
Has anyone gotten this to work with File attachments?
I have the file sitting in the same directory as the batch file.
I tried using the file name and the file name with the whole path
Both times it didn't even send the email.
I have the file sitting in the same directory as the batch file.
I tried using the file name and the file name with the whole path
Both times it didn't even send the email.
Code: Select all
set fileattach=Test.txt
or
set fileattach="C:\Users\Squash\batch files\email\Test.txt"
Re: Emailing with batch
Ignore the ID 10 T error.
I was double quoting. VBscript was putting quotes around the variable as well.
I was double quoting. VBscript was putting quotes around the variable as well.
Re: Emailing with batch
Greetings All,
For what it's worth:
Editing the script by foxidrive using the lines presented in the code box I was
successful in sending email using Yahoo.com.
Best wishes all!
For what it's worth:
Editing the script by foxidrive using the lines presented in the code box I was
successful in sending email using Yahoo.com.
Code: Select all
set Serv=smtp.mail.yahoo.com
set Auth=your_full_address@yahoo.com
echo >>%vbsfile% .Item ("%cdoSchema%/smtpserverport") = 587
echo >>%vbsfile% .Item ("%cdoSchema%/smtpusessl") = False
Best wishes all!