1

I have a zip file called data.zip and I would like to know if there is a batch code that can email it to example@test.com It is part of a program so if it includes extra software I must be allowed to distribute it with the software. It could be sent as a attachment. The batch file is elevated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
09stephenb
  • 9,358
  • 15
  • 53
  • 91
  • No it doesn't send files that is just text – 09stephenb Jan 13 '14 at 12:16
  • The accepted answer (using BLAT) will support sending attachments as well. There are [questions on SO](http://stackoverflow.com/questions/1172200/how-can-i-send-a-pdf-file-as-blat-attachment) about using BLAT with attachments as well. – RB. Jan 13 '14 at 12:20

1 Answers1

5

(from a Usenet post) 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 bill@gmail.com sue@gmail.com "This subject is about emails" "This is the body of the email" smtp.gmail.com bill@gmail.com password "d:\folder\attachment.txt"

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

::email.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::
@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%
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
foxidrive
  • 40,353
  • 10
  • 53
  • 68