2012-03-08 6 views
0

非常に多くのコードを残念に思っていますが、このフォームに問題があります。私はそれを構成するためにあらゆる方法を試しましたが、送信することはできません。メッセージ本体と一緒に電子メールを送信するだけですが、送信するたびにエラー(catchブロックから来る)が表示されます。基本フォームを送信しようとするとSMTPの問題が発生する

これはC#ASP.NETです。

私は開発が初めてで、助けていただければ幸いです。前もって感謝します!

protected void submitButton_Click(object sender, EventArgs e) 
{ 
    if (Page.IsValid) 
    { 
     string messageBody = "//numerous textboxes, dropdown lists, and checkboxes"; 

     SmtpClient smtp = new SmtpClient(); 
     MailMessage message = new MailMessage(); 
     message.IsBodyHtml = false; 

     try 
     { 
      // Prepare to and from e-mail addresses 
      MailAddress fromAddress = new MailAddress("[email protected]");     
      MailAddress toAddress = new MailAddress(emailTextBox.Text); 

      message.From = fromAddress; 
      message.To.Add(toAddress); 
      message.Subject = "Contact Form Email"; 
      message.Body = messageBody; 

      // Server details 
      smtp.Host = "email.goidp.com"; 
      // Credentials 
      smtp.UseDefaultCredentials = true; 
      // Send the email 
      smtp.Send(message);     

      // Inform the user 
      noticeLabel.Visible = true; 
      noticeLabel.Attributes.CssStyle.Add("display", "block"); 
      //noticeLabel.Text = "E-mail sent"; 
      noticeLabel.Text = "Thank you, we have received your information and will be in touch soon."; 

      // and clear the form 
      fullNameTextBox.Text = String.Empty; 
      companyTextBox.Text = String.Empty; 
       //many others, this is just to give the idea; 

     } 
     catch (Exception ex) 
     { 
      errorLabel.Text = "Error sending e-mail:<br/>\n" + ex.Message; 
      Response.Redirect("estimate-error.html?error=1"); 
      errorLabel.Visible = true; 
      errorLabel.Attributes.CssStyle.Add("display", "block"); 
      errorLabel.Text = "Error sending e-mail:<br/>\n" + ex.Message; 
     } 
    } 
    else 
    { 
     //errorLabel.Text = "Error sending e-mail. Check required fields<br/>"; 
     //Response.Redirect("estimate-error.html?error=2"); 
     errorLabel.Visible = true; 
     errorLabel.Attributes.CssStyle.Add("display", "block"); 
     errorLabel.Text = "Error sending e-mail. Check required fields<br/>"; 
    } 
} 

私はこのサイトを初めて利用しているので、私はもっと情報を投稿する必要があります。ありがとうございました!

+2

どのようなエラーが表示されますか? – alf

+0

これはcatchブロックからの一般的なエラーです。 「電子メールの送信中にエラーが発生しました:要求の送信に失敗しました」と表示されます。 – Peter

+2

catchブロックの最初の行にブレークポイントを設定し、例外を調べることができます。詳細な情報が含まれているか、内部の例外が含まれている必要があります – alf

答えて

0

SMTPオブジェクトの資格情報を設定する必要があります。

smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "PasswordForEmail"); 

がんばろう!

関連する問題