Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

PS 2.0 Mail versenden mit Attachment und credentials - verzweifele gleich

$
0
0

Hallo,

ich versuche jetzt seit Stunden mit Hilfe von Google und Try and Error dieses Schnippsel zum laufen zu bringen.

Habe PowerShell 2.0 installiert und kann auch nicht abdaten derzeit also muss es damit gehne.

#EMail 
$smtp = new-object Net.Mail.SmtpClient("smtp.xxxx.int")
$attachment = "C:\temp\amd\_logfile.txt"
#Auth Stuff
$smtpuser = new-object System.Net.networkCredential 
$smtpuser.domain = "smtpuserdomain" 
$smtpuser.username = "smtpusername"
$smtpuser.password = "xxxxxxxxxx"
$smtp.Credentials = $smtpuser
$smtp.Attachments.Add($attachment)
$smtp.Send("absender@xxxxxxx.int", "empfänger@xxxxxx.de", "PowerShell Email", "This is a email from powershell")

wenn ich dieses Script ausführe bekomme ich folgende Fehlermeldung:

You cannot call a method on a null-valued expression.
At C:\temp\amd\mail2.ps1:12 char:22
+ $smtp.Attachments.Add <<<< ($attachment)
    + CategoryInfo          : InvalidOperation: (Add:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Die Datei ist verhanden. Was ist ist hier falsch?


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>