2017-01-23 18 views
1

電子メールを送信しようとしましたが、エラーメッセージが表示されます。私はpowershell 4.0を持っています。私はPrimalFormsで作られたGUIを使用しています。あなたが見ることができるように、私は2つの異なるメールホスティング業者から送信しようとします。 GmailやHotmailのPowershell Send Mailエラーメッセージ

エラーメッセージ:

Send-MailMessage : Die E-Mail-Nachricht kann nicht gesendet werden, da kein SMTP-Server angegeben wurde. Sie müssen entweder mit dem 
SmtpServer-Parameter oder der $PSEmailServer-Variablen einen SMTP-Server angeben. 
In Zeile:118 Zeichen:9 
+   Send-MailMessage -From "$textBox_From.text" -To "$textBox_To. ... 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (:) [Send-MailMessage], InvalidOperationException 
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.SendMailMessage 

-Body : Die Benennung "-Body" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren Programms erkannt. 
Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und wiederholen Sie den Vorgang. 
In Zeile:119 Zeichen:9 
+   -Body "$textBox_Text.text" -SmtpServer "mail.google.com" -por ... 
+   ~~~~~ 
    + CategoryInfo   : ObjectNotFound: (-Body:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

私のPowerShellのコード:

$button_MailSenden_OnClick = { 

    if (($textBox_From.TextLength -eq 0) -or 
     ($textBox_To.TextLength -eq 0) -or 
     ($textBox_Subjekt.TextLength -eq 0) -or 
     ($textBox_Text.TextLength -eq 0)) { 

     [System.Windows.Forms.MessageBox]::Show("Bitte füllen Sie alle Kriterien aus." , "Combat 19") 

     #Gmail 
    } elseif ($radioButton_Gmail.Checked) { 

     Send-MailMessage -From "$textBox_From.text" -To "$textBox_To.text" -Subject "$textBox_Subjekt.text" 
     -Body "$textBox_Text.text" -SmtpServer "mail.google.com" -port "587" 

     [System.Windows.Forms.MessageBox]::Show("Mail gesendet!" , "Combat 19 - Gmail") 

     #Hotmail 
     } elseif ($radioButton_Hotmail.Checked) { 

     Send-MailMessage -From "$textBox_From.text" -To "$textBox_To.text" -Subject "$textBox_Subjekt.text" 
     -Body "$textBox_Text.text" -SmtpServer "smtp.live.com" -port "487" 

     [System.Windows.Forms.MessageBox]::Show("Mail gesendet!" , "Combat 19 - Hotmail") 

    } 
} 
+0

英語のエラーメッセージを使用してください。 イギリスの旗艦、ドイツの旗、Leute helfen。 – hering

+0

'Send-MailMessage'と' -Body ... 'の間の改行を削除します。 –

+0

これは、-bodyがコマンドレットではないと言います。私はPowerGuiで開くのではなく、smtpサーバに接続していないようです... –

答えて

2

-BodySend-MailMessageためのパラメータであるので、それらの両方が同じ行にする必要があります。コードを貼り付けて&をコピーするときにバッククォートを忘れた可能性があります(バックティックでは長い行が折れることがあります)。私は自分のスニペットにいくつか入れて、注意してください:)。

また、使用する値のほとんどを引用符で囲む必要はありません。

例えば、これを試してみてください:

$button_MailSenden_OnClick = { 

    if (($textBox_From.TextLength -eq 0) -or 
     ($textBox_To.TextLength -eq 0) -or 
     ($textBox_Subjekt.TextLength -eq 0) -or 
     ($textBox_Text.TextLength -eq 0)) { 

     [System.Windows.Forms.MessageBox]::Show("Bitte füllen Sie alle Kriterien aus." , "Combat 19") 

     #Gmail 
    } elseif ($radioButton_Gmail.Checked) { 

     Send-MailMessage -From $textBox_From.text ` 
         -To $textBox_To.text ` 
         -Subject $textBox_Subjekt.text ` 
         -Body $textBox_Text.text ` 
         -SmtpServer "mail.google.com" ` 
         -Port "587" 

     [System.Windows.Forms.MessageBox]::Show("Mail gesendet!" , "Combat 19 - Gmail") 

     #Hotmail 
     } elseif ($radioButton_Hotmail.Checked) { 

     Send-MailMessage -From $textBox_From.text ` 
         -To $textBox_To.text ` 
         -Subject $textBox_Subjekt.text ` 
         -Body $textBox_Text.text ` 
         -SmtpServer "smtp.live.com" ` 
         -Port "487" 

     [System.Windows.Forms.MessageBox]::Show("Mail gesendet!" , "Combat 19 - Hotmail") 

    } 
} 
関連する問題