发送外卡作为附件

时间:2015-06-03 01:50:58

标签: batch-file vbscript cmd automation

我正在尝试执行一个批处理,它将在特定日期发送附件。 此批处理文件(Date.bat)将基于当前日期将文件复制到新文件夹:

copy C:\test\output.csv C:\test2\output%date:~-4,4%_%date:~-10,2%_%date:~7,2%.csv

email.vbs脚本会向用户发送附件:

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "test123" 
objMessage.From = "spartan@test.com" 
objMessage.To = "test123@test.com" 
objMessage.HTMLBody = strHTML
objMessage.AddAttachment "c:\test\output.csv"

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "spartan-dev"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

例如,当我在星期五执行Date.bat时,星期五的附件将在下周一发送。

1 个答案:

答案 0 :(得分:2)

使用任务计划程序。

显示如何连接到计算机并列出根文件夹中的任务。

Set TS = CreateObject("Schedule.Service")
TS.Connect("Serenity")

Set rootFolder = TS.GetFolder("\")

Set tasks = rootFolder.GetTasks(0)

If tasks.Count = 0 Then 
    Wscript.Echo "No tasks are registered."
Else
    WScript.Echo "Number of tasks registered: " & tasks.Count

    For Each Task In Tasks
    A=Task.Name
    A = A & " " & Task.NextRunTime
    A = A & " " & Task.LastTaskResult
    wscript.echo A
    Next
End If

您也可以使用批处理文件。请参阅schtasks /?

这是来自帮助列出文件夹中的文件。

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder("c:\")
   Set fc = f.Files
   For Each f1 in fc
      s = s & f1.name 
   Next
   Msgbox s