2016-05-30 9 views
0

Ich möchte in der Lage sein, eine Anhangsdatei zu senden, indem ich sie einfach auf ein Skript lege.Wie wird der Dateipfad und die Erweiterung von Drag & Drop abgerufen? BVS

ich diese gefunden haben, der die Datei sendet (es funktioniert für mich):

Set fso=CreateObject("Scripting.FileSystemObject") 
strSMTP="smtp.gmail.com" 
strSubject="[email protected]" 
strSubject2="Attachment file" 
strBody="-" 
strAttach="FILEPATH" 
If fso.FileExists(strAttach) then 
Set iMsg = CreateObject("CDO.Message") 
Set iConf = CreateObject("CDO.Configuration") 
iConf.Load -1 ' CDO Source Defaults 
Set Flds = iConf.Fields 
With Flds 
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" 
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 
.Update 
End With 
With iMsg 
Set .Configuration = iConf 
.To = "[email protected]" 
.CC = "" 
.BCC = "" 
.From = "[email protected]" 
.Subject = strAttach 
.TextBody = strBody 
.AddAttachment strAttach 
.Send 
End With 
Set iMsg = Nothing 
Set iConf = Nothing 
Else 
MsgBox "The specified attachment does not exist" 
End if 

Was brauche ich eine Änderung dieses Skript, das mir die sechste Zeile strAttach="FILEPATH" mit dem Pfad ändern können und die Erweiterung der Datei, die darauf fällt und dann das "send mail script" ausführt.

Gefunden diese zwei Links zu meiner Frage, aber ich weiß nicht, wie man sie verwendet, hoffe, dass diese auch Ihnen helfen können. How to get the fully qualified path for a file in VBScript? http://vba-tutorial.com/parsing-a-file-string-into-path-filename-and-extension/

Die erste zeigt nur den Dateipfad und die Erweiterung auf einem neuen Fenster, aber ich brauche es in der 6. Zeile überschrieben. Könnte mir jemand helfen? Ich bin kein Programmierer, möchte nur die Dateien an meine eigene Mail senden, weil ich sie später auf einem anderen Computer drucken muss.

Entschuldigung für mein Englisch. Ich bin kein Muttersprachler. Danke im Voraus!

Antwort

0

Verwenden Arguments Property (WScript Object):

Die Arguments Eigenschaft enthält die WshArguments Objekt (eine Sammlung von Argumenten ). Verwenden Sie einen nullbasierten Index, um einzelne Argumente aus dieser Auflistung abzurufen.

Set fso=CreateObject("Scripting.FileSystemObject") 
strSMTP="smtp.gmail.com" 
strSubject="[email protected]" 
strSubject2="Attachment file" 
strBody="-" 

''''''''''''''''''''''''''''''''''' strAttach="FILEPATH" 
Set objArgs = WScript.Arguments 
For ii = 0 to objArgs.Count - 1 
    SendMyMail fso.GetAbsolutePathName(CStr(objArgs(ii))) 
Next 

Sub SendMyMail(ByVal strAttach) 
    If fso.FileExists(strAttach) then 
     Set iMsg = CreateObject("CDO.Message") 
     Set iConf = CreateObject("CDO.Configuration") 
     iConf.Load -1 ' CDO Source Defaults 
     Set Flds = iConf.Fields 
     With Flds 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
     .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password" 
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 
     .Update 
     End With 
     With iMsg 
     Set .Configuration = iConf 
     .To = "[email protected]" 
     .CC = "" 
     .BCC = "" 
     .From = "[email protected]" 
     .Subject = strAttach 
     .TextBody = strBody 
     .AddAttachment strAttach 
     .Send 
     End With 
     Set iMsg = Nothing 
     Set iConf = Nothing 
    Else 
     MsgBox strAttach & vbCrLf & "The specified attachment does not exist" 
    End if 
End Sub 

Sollte

Bitte überprüfen Sie Paul Sadowskis Artikel Sending email with CDO, um Ihren Code zu vereinfachen.

+0

Vielen Dank, es hat funktioniert. Ich werde diesen Artikel auch überprüfen. Einen schönen Tag noch. –