Mailversand mit vbs, Ereiterung damit man Datei mitsenden kann
Hallo Forum,
habe eine .vbs Datei mit der ich Mails versenden kann.
Diese rufe ich so auf:
cscript Mailer.vbs "Testmail %computername%" "test %computername%"
Ich muß nun zusätzlich zur definierbaren Betreffszeile eine / mehrere Datei(en) anfügen können, am liebsten per Variablen.
Wie kann ich das Skript entsprechend umbauen, bin nicht so der VB Experte...
Vielleicht hilt mir jemand, wäre tool
In einem Skript definiere ich z. B. vorher:
set pfad=c:\log
set Anhanga=%Pfad%\status-%date%.log
set Anhangb=c:\versand.txt
...
Möchte also die vb in etwas so aufrufen:
cscript Mailer.vbs "Testmail %computername%" "test %computername%" %Anhanga% %Anhangb% %Anhangc% %Anhangd%
Inhalt der vbs:
' this file is only an example for how to write
' such a script
' you can use it and modify the values for smtpserver
' sendusername and sendpassword
Option Explicit
Dim objArgs, strMsgBody, subject, iMsg, iConf, Flds
Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
strMsgBody = objArgs(0)
subject = objArgs(1)
else
strMsgBody = "The server needs your attention"
subject = "Attention !"
End If
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
strMsgBody = subject & " - " & FormatDateTime(Now())
subject = subject & " - " & FormatDateTime(Now())
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 50
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
' change the following values
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.118.12.171"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Send"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Sender"
Flds.Update
With iMsg
Set .Configuration = iConf
.To = "stefan@test.de"
.From = "Admin@server1"
.Subject = subject
.TextBody = strMsgBody
.Send
End With
'WScript.Echo "Send mail completed."
WScript.Quit(0)
Danke !!
Gruß Stefan
habe eine .vbs Datei mit der ich Mails versenden kann.
Diese rufe ich so auf:
cscript Mailer.vbs "Testmail %computername%" "test %computername%"
Ich muß nun zusätzlich zur definierbaren Betreffszeile eine / mehrere Datei(en) anfügen können, am liebsten per Variablen.
Wie kann ich das Skript entsprechend umbauen, bin nicht so der VB Experte...
Vielleicht hilt mir jemand, wäre tool
In einem Skript definiere ich z. B. vorher:
set pfad=c:\log
set Anhanga=%Pfad%\status-%date%.log
set Anhangb=c:\versand.txt
...
Möchte also die vb in etwas so aufrufen:
cscript Mailer.vbs "Testmail %computername%" "test %computername%" %Anhanga% %Anhangb% %Anhangc% %Anhangd%
Inhalt der vbs:
' this file is only an example for how to write
' such a script
' you can use it and modify the values for smtpserver
' sendusername and sendpassword
Option Explicit
Dim objArgs, strMsgBody, subject, iMsg, iConf, Flds
Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
strMsgBody = objArgs(0)
subject = objArgs(1)
else
strMsgBody = "The server needs your attention"
subject = "Attention !"
End If
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
strMsgBody = subject & " - " & FormatDateTime(Now())
subject = subject & " - " & FormatDateTime(Now())
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 50
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
' change the following values
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.118.12.171"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Send"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Sender"
Flds.Update
With iMsg
Set .Configuration = iConf
.To = "stefan@test.de"
.From = "Admin@server1"
.Subject = subject
.TextBody = strMsgBody
.Send
End With
'WScript.Echo "Send mail completed."
WScript.Quit(0)
Danke !!
Gruß Stefan
Please also mark the comments that contributed to the solution of the article
Content-Key: 203672
Url: https://administrator.de/contentid/203672
Printed on: April 25, 2024 at 10:04 o'clock
6 Comments
Latest comment
Moin.
Sorry das muss
.AddAttachment "c:\versand.txt"
ohne ist gleich sein.
(vgl. Vbs - Email versenden mit Anhang?)
HTH
MK
Sorry das muss
.AddAttachment "c:\versand.txt"
ohne ist gleich sein.
(vgl. Vbs - Email versenden mit Anhang?)
HTH
MK