VBSCRIPT로 메일 보내기

4165 단어 VBScript
Email.bat---------------
REM send Email
REM ==========
set [email protected]

set [email protected]

set emailSubject=Email Testing
set emailBodyContent=20131007_testMail.txt
set ipaddress=11.11.11.11

%windir%\system32\wscript.exe sendmail.vbs -t "%emailRecvList%" -f "%emailFrom%" -s "%emailSUbject%" -b "%emailBodyContent%"  -p "%ipaddress%"

sendmail.vbs----------------------
   '--------------------------------------------------
   '
   ' Sends email from the local SMTP service using CDO objects
   '
   ' Usage:
   '   sendmail -t <to> -f <from> -s "<subject>" -b "<message file>" -p <ipaddress>
   '   sendmail [-help|-?]
   '
   '--------------------------------------------------

   Option Explicit
   On Error Resume Next

   Dim objSendMail, oArgs, ArgNum, AttNum, objFSO, objTextFile
   Dim strTo, strFrom, strSubject, strBody, strIP

   Const ForReading = 1
   Set oArgs = WScript.Arguments
   ArgNum = 0
   AttNum = 0

   While ArgNum < oArgs.Count
      Select Case LCase(oArgs(ArgNum))
         Case "-to","-t":
            ArgNum = ArgNum + 1
            strTo = oArgs(ArgNum)
         Case "-from","-f":
            ArgNum = ArgNum + 1
            strFrom = oArgs(ArgNum)
         Case "-subject","-s":
            ArgNum = ArgNum + 1
            strSubject = oArgs(ArgNum)
         Case "-body","-b":
            ArgNum = ArgNum + 1
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objTextFile = objFSO.OpenTextFile (oArgs(ArgNum), ForReading)
            strBody = objTextFile.ReadAll
            objTextFile.Close
         Case "-ipaddress","-p":
            ArgNum = ArgNum + 1
            strIP = oArgs(ArgNum)
            AttNum = AttNum + 1
         Case "-help","-?":
            Call DisplayUsage
         Case Else:
            Call DisplayUsage
      End Select
      ArgNum = ArgNum + 1
   Wend

   If oArgs.Count=0 Or strTo="" Or strFrom="" Or _
         strSubject="" Or strBody="" or strIP="" Then
      Call DisplayUsage
   Else
      Set objSendMail = CreateObject("CDO.Message")
         objSendMail.From = strFrom
         objSendMail.To = strTo
         objSendMail.Subject = strSubject
         objSendMail.Textbody = strBody & vbCrLf & vbCrLf
         objSendMail.Configuration.Fields.Item _
             ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
         objSendMail.Configuration.Fields.Item _
             ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
             strIP 
         objSendMail.Configuration.Fields.Item _
             ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
         objSendMail.Configuration.Fields.Update
         objSendMail.Send
      Set objSendMail = Nothing
   End If

   ' Display the usage for this script
   Sub DisplayUsage
      WScript.Echo "Usage:"
      WScript.Echo "  sendmail -t <to address> -f <from address> -s " & _
         Chr(34) & "<subject>" & Chr(34) & " -b " & Chr(34) & _
         "<message file>" & Chr(34) & " -a " & Chr(34) & "<ipaddress>"
      WScript.Echo "  sendmail [-help|-?]"
      WScript.Echo ""
      WSCript.Quit
   End Sub

 
 
 
 

좋은 웹페이지 즐겨찾기