albertminrich
Goto Top

Vbs - Email versenden mit Anhang?

Hallo,

eine Email per vbs versenden ist kein Problem:

Set objEmail = CreateObject("CDO.Message")  
objEmail.From = "irgendwer"  
objEmail.To = "ich@meinedomain.de"  
objEmail.Subject = "vbs Test"   
objEmail.Textbody = "ein vbs-test."  
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "meinsmtpserver"   
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
objEmail.Configuration.Fields.Update
objEmail.Send

Funktioniert einwandfrei. Jetzt möchte ich einen Anhang mitversenden.
Bei Google stosse ich auf diese Zeile:
objEmail.AddAttachment = "c:\test.txt"  

Leider meckert mein Script:
"Laufzeitfehler in Microsoft VBScript: Das Objekt unterstützt diese Eigenschaft oder Methode nicht.: 'objEmail.AddAttachment'


Was mach ich falsch?

Danke und Gruß
AlbMin

Content-Key: 180527

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

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

Member: Pjordorf
Pjordorf Feb 14, 2012 at 15:46:08 (UTC)
Goto Top
Hallo,

Zitat von @AlbertMinrich:
eine Email per vbs versenden ist kein Problem:
Welches OS?

Leider meckert mein Script:
Welche Version(en) verwendest du?

Geht folgender Code? IP anpassen.
Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message

'Add the Project Reference Miscrosoft CDO WINDOWS FOR 2000  
'lobj_cdomsg.Configuration.Fields(cdoSMTPServer)="10.16.100.189"  
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = "10.16.100.19"  
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = "Wallaby.stuart@wallabycounty.com,mahahra.ramaha@wallabycounty.com"  
lobj_cdomsg.From = "mahahra.ramaha@wallabycounty.com"  
lobj_cdomsg.Subject = "filename Sent to www.???.com "  
lobj_cdomsg.TextBody = "File FTP LOG ATTACHED."  
lobj_cdomsg.AddAttachment ("\\server\filefolder\FTPlog.TXT")  
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing

Gruß,
Peter
Member: AlbertMinrich
AlbertMinrich Feb 14, 2012 at 15:59:30 (UTC)
Goto Top
Windows XP SP3
WSH-Version ist 5.7

Dein Code
Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = "meinsmtpserver"  
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = cdoSendUsingPort
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = "ich@meinedomain.de"  
lobj_cdomsg.From = "mir"  
lobj_cdomsg.Subject = "betrefftest"  
lobj_cdomsg.TextBody = "test"  
lobj_cdomsg.AddAttachment ("c:\test.txt")  
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing

meckert leider gleich bei der ersten Zeile:
"Kompilierungsfehler in Microsoft VBScript: Anweisungsende erwartet"

Sorry, ich hab eine Zeile vergessen. Test eben nochmal. Melde mich gleich wieder.
Quatsch, das war ja eine auskommentierte Zeile.

Also, wie gesagt, Fehler gleich bei der ersten Zeile.
Member: bastla
bastla Feb 14, 2012 at 16:22:03 (UTC)
Goto Top
Hallo AlbertMinrich!
Fehler gleich bei der ersten Zeile.
Dann lass sie (oder zumindest alles ab "As") doch einfach weg face-wink - "Dim" kann unter VBS keine Datentypen festlegen und hat damit ohnehin bestenfalls zusammen mit einem "Option Explicit" Sinn ...

Grüße
bastla
Member: Pjordorf
Pjordorf Feb 14, 2012 at 19:39:18 (UTC)
Goto Top
Hallo,

Zitat von @AlbertMinrich:
Also, wie gesagt, Fehler gleich bei der ersten Zeile.
Sorry. wie bastla schon anmerkte DIM kommt da nicht so gut. Ich habe aber mal eben getestet (ist schon länger her das ich den Code benutzt hatte in vb?) und folgender code geht in vbs (cscript testmail.vbs).
set lobj_cdomsg = CreateObject("CDO.Message")  
lobj_cdomsg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
lobj_cdomsg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "dein.smtp.server.oder.ip"   
lobj_cdomsg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = "gueltiger.mail@name.tld, wallaby.stuart@wallabycounty.com, mahahra.ramaha@wallabycounty.com"  
lobj_cdomsg.From = "gueltiger.absender@name.tld"  
lobj_cdomsg.Subject = "filename Sent to www.???.com "  
lobj_cdomsg.TextBody = "File FTP LOG ATTACHED and nothing else."  
lobj_cdomsg.AddAttachment ("C:\testing\test.txt")  
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing
Deinen Fehler mit den Anhängen habe ich jetzt auch in deinem ersten Code gefunden (manchmal ist man einfach Blind). Dort ist ein = zuviel. Mach einfach ein
objEmail.AddAttachment "c:\test.txt"  
anstelle deines
objEmail.AddAttachment = "c:\test.txt" ' FALSCH  

Gruß,
Peter
Member: AlbertMinrich
AlbertMinrich Feb 14, 2012 at 20:02:37 (UTC)
Goto Top
> objEmail.AddAttachment = "c:\test.txt" ' FALSCH  
> 

Oh Mann, sorry.
Jetzt klappts natürlich.

Danke und Gruß
Martin