using Windows send-to for creating a one step send to>zip>to email

爱⌒轻易说出口 提交于 2019-12-25 03:45:31

问题


In another post on Stack Overflow a user named James L. presented a useful script for adding 7-Zip to the Send to Options in Windows. I was wondering how hard it would be to take that same principle one more step by sending the results on to be attached to an email? Most of the zips I create are done in order to email them and this would cut that down to one click. The only obstacle being that it could not create a self-extracting ".exe" file to be attached.


回答1:


Here are three scripts you can stich together.

CreateBlankZip.vbs Zipname passed as a parameter, use quotes if spaces in name.

Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
    BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip

Add folder to zip. DestinationZip SourceFolder

Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"

Send mail and attach file.

Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = "dc@gmail.com"

emailObj.To       = "dc@gmail.com"

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")    = "MyName"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "Ppassword1"
emailConfig.Fields.Update

emailObj.Send

If err.number = 0 then Msgbox "Done"


来源:https://stackoverflow.com/questions/35108798/using-windows-send-to-for-creating-a-one-step-send-tozipto-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!