2016-06-20 3 views
0

사용자가 폴더에 파일을 업로드 할 때 모든 사용자에게 즉시 이메일을 보내야합니다. 기존 코드는 다음과 같이 작동합니다. 우리는 오전 11시에 매일 실행되는 작업 스케줄러를 가지고 있으며 파일은 수정 된 날짜를 필터링합니다. 내 목표는 사용자가 파일을 업로드 할 때 전자 메일을 보내지 만 수정 된 날짜가 업로드 날짜가 아닌 파일 생성 날짜이기 때문에 1 시간 또는 매 5 분 동안 스케줄러를 실행할 수 없습니다. 아래 폴더에 코드가 업데이트되어 사용자가 즉시받을 수 있도록하는 코드가 있습니다. 파일 \ 스크립트 (노트 백 슬래시 다시 두 배로 다음 두 배로해야 함) 매 10 초합니다 (within 10를) 생성되는 :파일 업로드시 즉시 이메일을 보내는 방법

Dim objFso 
Set objFso = CreateObject("Scripting.FileSystemObject") 

Dim strPath, yr, mnt 
yr = CStr(Year(Now)) 
mnt = CStr(Month(Now)) 
strPath = "c:\\users\upload files\email " + yr 

Dim strContent 
strContent = "" 
Set objFolder = objFso.GetFolder(strPath) 

For Each objFile In objFolder.Files 
    If objFso.GetExtensionName (objFile.Path) = "pdf" Then 
     If objFile.DateLastModified > dateadd("hr", -24, Now) Then 
      strContent = strContent + "<li>" + _ 
       "<a href=""C://Users/uploadfiles/email/" + yr + "/" + _ 
       objFile.Name + """>" + objFile.Name + "</a></li>" 
      MsgBox(strContent) 
     End If 
    End If 
+0

코드가 불완전하여 이메일을 보내려하지 않습니다. 그래서 VBScript에서 메일을 보내는 많은 예제가 있습니다. 먼저 직접 시도하십시오. 우리는 당신을 위해 일하기 위해 여기에 온 것이 아닙니다. –

+0

안녕하세요 @AnsgarWiechers 이메일을 보내는 코드가 있습니다. 그냥 사용자가 업로드 할 때 바로 fles를 고르고 싶습니다. – sai

답변

1
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ 
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent= 'Win32_Directory.Name=""c:\\\\scripts""'") 
Do 
    Set objLatestEvent = colMonitoredEvents.NextEvent 
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent 
Loop 

이것은 C를 모니터링합니다.

Set emailObj  = CreateObject("CDO.Message") 
emailObj.From  = "[email protected]" 

emailObj.To  = "[email protected]" 

emailObj.Subject = "Test CDO" 
emailObj.TextBody = "Test CDO" 

emailObj.AddAttachment "c:\windows\win.ini" 

Set emailConfig = emailObj.Configuration 

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")  = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Username" 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password" 
emailConfig.Fields.Update 

emailObj.Send 

If err.number = 0 then Msgbox "Done" 
+0

안녕하세요. 왜 여기에 가장해야하는지 알려주세요. 자동으로 실행되거나 수동으로 실행해야합니까 ?? – sai

+0

생략 할 수 있으므로 가장이 가장입니다. 그것은 보안 권한을 가진 당신과 같은 행동을 의미합니다. –

+0

당신을 가장하거나 익명의 두 가지 선택이 있습니다. 거의 아무것도 익명으로 작동하지 않습니다. WMI는 이미 실행 중이므로 사용할 수없는 자체 보안 컨텍스트가 있습니다. 그래서 그것은 당신을 사칭하여 당신이 할 수있는 일을 할 수있게합니다. –