presidente
Goto Top

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

Content-Key: 203672

Url: https://administrator.de/contentid/203672

Printed on: April 25, 2024 at 10:04 o'clock

Member: thaenhusen
thaenhusen Mar 20, 2013 at 16:10:03 (UTC)
Goto Top
Moin.

Das sollte z.B. mittels

.AddAttachment = "c:\versand.txt"

nach der Zeile

.TextBody = strMsgBody

funktionieren.

Für mehrere Anhänge .AddAttachment mehrfach aufrufen.

HTH
MK
Member: presidente
presidente Mar 20, 2013 at 21:01:49 (UTC)
Goto Top
N"Abend...

klappt leider nicht...

Send_Mail-test.vbs(43, 7) Laufzeitfehler in Microsoft VBScript: Das Objekt unterstützt diese Eigenschaft oder Methode nicht.:
'AddAttachment'

Was kann das sein. bzw hat jemand ein Skript, mit dem ich Anhaenge versenden kann, benötige aber unbedingt Authentifizierung für den SMTP ?!?!?


Danke
Member: thaenhusen
thaenhusen Mar 21, 2013 at 11:24:22 (UTC)
Goto Top
Moin.

Sorry das muss

.AddAttachment "c:\versand.txt"

ohne ist gleich sein.

(vgl. Vbs - Email versenden mit Anhang?)

HTH
MK
Member: presidente
presidente Mar 21, 2013 at 15:21:47 (UTC)
Goto Top
Hallo,

super Sache funktioniert nun. Jedoch kommt es nicht mit Variablen zurecht. Muß aber die Variable übergeben:


Rufe die vbs deswegen innerhalb einer Batch auf:

cscript ./MAIL/Send_Mail-test.vbs "test" "test" "c:\Exportlauf-%DATE%.log"

die VBS hab ich so angepaßt:

' 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, attachment, iMsg, iConf, Flds

Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
strMsgBody = objArgs(0)
subject = objArgs(1)
attachment = objArgs(2)
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 = strMsgBody
subject = subject & " - " & FormatDateTime(Now())
AddAttachment = attachment

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.168.0.1"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Mail"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Mail"
Flds.Update

With iMsg
Set .Configuration = iConf
.To = "test@test.de"
.From = "test@server1"
.Subject = subject
.TextBody = strMsgBody
.AddAttachment = attachment
.Send
End With

'WScript.Echo "Send mail completed."

WScript.Quit(0)

Folgender Fehler erscheint:
(26, 1) Laufzeitfehler in Microsoft VBScript: Variable ist nicht definiert: 'AddAttachment'


Kannst du/ihr nochmal kurz helfen, danke

Gruß Stefan
Member: thaenhusen
thaenhusen Mar 21, 2013 at 15:31:53 (UTC)
Goto Top
Moin.

Statt

.AddAttachment = attachment

versuch mal

.AddAttachment attachment

HTH
MK
Member: presidente
presidente Mar 21, 2013 at 15:32:56 (UTC)
Goto Top
Hi, du hast Recht, habs auch grad selber rausgefunden.

danke dir trotzdem.

gruß stefan