很多時候 想要讓一些工作可以自動提醒
之前我是使用vbs讓他發mail
但就太故定型式了 所以寫改了一隻比較活動式的vbs來讓大家參考
可以加在批次檔中
這樣只要修改批次檔即可工作
應網友需求 說要有可以驗證的地方
以下mb.bat為我拿下述修所部份 2006/09/25 加入
加入 HTML BODY 及 cc (寄件副本) 的部份
:: 快速夾檔寄信 :: mb.bat 所夾檔案::mb.bat@echo offREM ma.bat 2006/09/25REM 將雙引號中的變數改成你想要的即可if "%1" == "" goto :Useagerem s_mail所在位置 請給實際路徑 or 加到有path 的地方set execfile="s_mail.vbs" rem 發信者 帳號是亂打的 打打入自已的set mailfrom=/fr "a123test@gmail.com" rem 收件者 帳號是亂打的 打打入自已的set mailto=/to "a123test@gmail.com"rem 主旨set mailsub=/sub "MEBAK Send a File" rem 信件內容set mailmes=/mes "Send a File %1 _ %date%%time% "REM 驗證帳密set user=/muser "a123test"set password=/mpasswd "a123test"REM smtpServerset smtpServer=/s "smtp.gmail.com" rem /sh 觀看 /mail 發送 smtp驗證 smtp ssl 動作 (自行參考不一定全部都有) 以下是使用 gmail 的部份set other=/sh /mail /au /ssl /sport 465 :: 一般不用使用gmail 如下:: set other=/sh /mail /auREM 執行%execfile% %smtpServer% %mailto% %mailFrom% %user% %password% %mailsub% %mailmes% %other% /add %1Rem end Rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``goto :End:Useageecho plz Give a File echo example mb.bat "File"goto :End:end
----------ma.bat------------
REM ma.bat 2005'12'27
REM 將雙引號中的變數改成你想要的即可
REM 執行程式
set execfile="C:\Documents and Settings\Administrator\桌面\s_mail.vbs"
rem 發信者
set mailfrom=/fr "user@smtpmail.test.com"
rem 收件者
set mailto=/to "abc@hotmail.com;def@hotmail.com"
rem 主旨
set mailsub=/sub "mail sub aa"
rem 內文 內文可以夾文字也可以用一般的字串REM 字串型
rem set mailmes=/mes "HI My name is CC"
rem 檔案型 在/mes 後面加上 file 加上檔名set mailmes=/mes file "C:\Documents and Settings\Administrator\桌面\新增文字文件.txt"REM 驗證帳密set user=/muser "user1"set password=/mpasswd "password"REM 夾檔案set add=/add "C:\Documents and Settings\Administrator\桌面\新增文字文件.txt"REM smtpServer
set smtpServer=/s "192.168.1.10"
rem /sh 觀看 /mail 發送 smtp驗證 smtp ssl 動作
/html 加入html body 的信件 (自行參考不一定全部都有)
set other=/sh /mail /au /ssl
REM 執行
%execfile% %smtpServer% %mailto%
%mailcc% %mailFrom%
%user% %password% %mailsub%
%add% %mailmes% %other%
Rem end
Rem ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
-----------S_mail.vbs---------------------
' *************************************************
' S_mail.vbs 2005'12'27
' S_mail.vbs /s 192.168.1.10 /to test@test.com.tw
/cc test@test.com.tw /fr log@MAIL /sub "testaa" /mes aaa /sh /MAIL
' edit 2006/01/04 ' edit 2006/01/07' edit 2006/01/12 ' edit 2006/12/07 ' *************************************************
Option Explicit
' *********************** DIM *********************
dim mailfrom,mailto,
mailcc,mailsub,mailmess,MXserver,mailsmtpport,
mailuser,mailpasswddim objEmail,msgerr
Dim stry,strm,strd,strtxt
dim fush,fuc
Dim strFlag,intState,i
Dim objFileSystem
dim FSO,objfile,ReadAllTextFiledim add,addfile,userpddim strsmptaut,smptaut,htmlchkdim strsmtpssl,smtpssl' ***********************EDIT ***********************
' *********************** PROGRAM ***********************
call argm
CALL funchk
' ***********************SUB PROGRAM ***********************
sub argm
if Wscript.arguments.Count > 1 then
add = 0userpd = 0mailsmtpport = 25
for i = 0 to Wscript.arguments.Count -1
select case LCase(Wscript.arguments.Item(i))
case "/s"
MXserver = LCase(Wscript.arguments.Item(i+1))
case "/to"
mailto = LCase(Wscript.arguments.Item(i+1))
case "/cc"mailcc = LCase(Wscript.arguments.Item(i+1))case "/fr"
mailfrom = LCase(Wscript.arguments.Item(i+1))
case "/sub"
Mailsub = LCase(Wscript.arguments.Item(i+1))
case "/mes"
mailmess = LCase(Wscript.arguments.Item(i+1))
if mailmess = "file" then Set FSO = CreateObject("Scripting.FileSystemObject")Set objfile = FSO.OpenTextFile(Wscript.arguments.Item(i+2),1)ReadAllTextFile = objfile.ReadAllobjfile.closeend ifcase "/add" add = 1addfile = LCase(Wscript.arguments.Item(i+1))case "/html"htmlchk=1case "/muser"userpd = userpd + 1 mailuser = LCase(Wscript.arguments.Item(i+1))case "/mpasswd"userpd = userpd + 1mailpasswd = Wscript.arguments.Item(i+1)case "/au"strsmptaut = "Yes"smptaut = 1 case "/ssl"strsmtpssl = "Yes"SmtpSSL = 1case "/sport"
mailsmtpport =int(Wscript.arguments.Item(i+1))
case "/sh"
fush = 1
case "/mail"
fuc = 1
end select
next
else
call usage
end if
end sub
sub funchk
if mailto = "" or mailfrom = "" or Mailsub = "" or mailmess = "" or MXserver = "" then
if mailfrom = "" then mailfrom = "/fr Mail From"
if mailto = "" then mailto = "/to Mail To"
if Mailsub = "" then Mailsub = "/sub Subject"
if mailmess = "" then mailmess = "/mes Message"
if MXserver = "" then MXserver = "/s Smtp Server"
call showlok
wscript.echo "You can type mal.vbs /? or mal.vbs "
wscript.quit
end if
if fush = 1 then call showlok
if fuc = 1 then call mlt
end sub
sub usage
wscript.echo ""
wscript.echo ""
wscript.echo "Executes a command."
wscript.echo ""
wscript.echo " SYNTAX: "
wscript.echo ""
wscript.echo " [/s ] "
wscript.echo " [/to ]
[/cc] [/fr ]"
wscript.echo " [/sub ] [/mes
| file FileName ] "
wscript.echo " [/sh ] [/mail ]"
wscript.echo " [/add ]"wscript.echo " [/au ]"wscript.echo " [/SSL ]"wscript.echo " [/html ]"wscript.quit
end sub
sub showlok
wscript.echo ""
wscript.echo "MAIL FROM : " & mailfrom
wscript.echo "MAIL TO : " & mailto
wscript.echo "MAIL SUB : " & Mailsub
wscript.echo "MAIL MESS : " & mailmess
wscript.echo "SMTP Server : " & MXserver
if smptaut = 1 then wscript.echo "SMTP Authenticate: " & strsmptaut
if smtpssl = 1 then wscript.echo "SMTP SSL: " & strSmtpSSL
if htmlchk=1 then wscript.echo " HtmlBody Send"wscript.echo
end sub
'*********
sub mlt
Set objEmail = CreateObject("CDO.Message")
if mailmess = "file" then mailmess = ReadAllTextFilewith objEmail
.From = mailfrom
.To = mailto
.cc = mailcc.Subject = mailsub
if htmlchk=1 then
.htmlbody=mailmess
else
.Textbody = mailmess
end if
'夾檔案
if add = 1 then .AddAttachment addfile end ifif userpd = 2 then.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailuser.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpasswdend ifif smptaut = 1 then.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1end if if smtpssl = 1 then.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = trueend if.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MXserver
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mailsmtpport
.Configuration.Fields.Update
.Send
end with
end sub
'**********
' end
文章定位: