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"
> 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.
******************************************************************************************