0

私のWebサイトには、「お問い合わせ」ページがあり、マネージャーが顧客に電子メールで返信できるようにしたいと考えています。すべてのプロセスはサーバー側にある必要があります。私はWebmatrix開発環境で作業していることに注意することが重要です...

それで、私のWeb開発を考えると、電子メールを送信する機能を追加するための簡単な方法は何ですか?

私のHTMLコードは次のとおりです。

foreach(var row in db.Query(displayApplicant,nameOfcustomer))
                {
                <tr>
                    <td class="dispExpertActScreen">@row.messegeID</td>
                    <td class="dispExpertActScreen">@row.name</td>
                    <td class="dispExpertActScreen">@row.email</td>
                    <td class="dispExpertActScreen">@row.isCustomer</td>
                    <td class="dispExpertActScreen">@row.userID</td>
                    <td class="dispExpertActScreen">@row.content</td>
                    <td class="dispExpertActScreen"><a href="#" onclick="answerBox('@row.messegeID','@row.userID')" style="color: #b04e4e">answer the question</a></td>
                    <td class="dispExpertActScreen"><a href="#" onclick="reqeustToDelete('@row.messegeID')" style="color: #b04e4e">remove</a></td>
                </tr>
                } 

javascript関数:(非表示フィールドに詳細を保存するため)

<script type="text/javascript">

function answerBox(messegeID,userID) {
        var msg = prompt('answer to customer:');
        document.getElementById('answer').value = msg;
        document.getElementById('ansMode').value = 'true';
        document.getElementById('msgID').value = messegeID;
        document.getElementById('user').value = userID;
        document.getElementById('ansMessege').submit();
    }

</script>

隠しフィールド:

<form method="post" id="ansMessege" style="font-size: medium; margin-top: 10%" dir="rtl">
    <input type="hidden" name="answer" id="answer" value="">
    <input type="hidden" name="msgID" id="msgID" value="">
    <input type="hidden" name="user" id="user" value="">
    <input type="hidden" name="ansMode" id="ansMode" value="">
</form> 

asp.netコード:

<%@ Import Namespace="System.Web.Mail" %>

@{
    Layout = "~/_ManagerLayout.cshtml";
    Page.Title = "Management Applications";

 }
@{
    var db = Database.Open("MyProjectSite");
    var display="no";
    var displayApplicant="";
    var nameOfcustomer="";
    var category="";
    var yesNo="";
     if(IsPost)
    {
     if(Request.Form["ansMode"] == "true")
          {
              var selectQuery="SELECT * FROM messegesFromCustomers";
              var id=Request.Form["msgID"];
              var msg=Request.Form["answer"];
              var user=Request.Form["user"];

              foreach(var row in db.Query(selectQuery))
              {
                  if(row.messegeID == Convert.ToInt32(id))
                  {
                      if(row.isCustomer == "yes")// **send the messege to customer account**
                      {
                          var insertQuery="UPDATE messegesFromCustomers SET answer=@0 WHERE messegeID=@1";
                          db.Execute(insertQuery,msg,id);
                          Response.Write("<script>alert('your answer sent successfully');</script>");
                          break;
                      }
                      else
                      {
                          // **Send messege to Occasional customer via email**
                         // **here I want to add code for sending email...**


                          string from = "ofirhgy@gmail.com";
                          string to = "ofirhgy@gmail.com";
                          string subject = "Hi!";
                          string body = "How are you?";
                          SmtpMail.SmtpServer = "mail.gmail.com";
                          SmtpMail.Send(from, to, subject, body);

                          break;
                      }
                  }
              }

          }

 }



}

ご覧のとおり、WebMail.Send(...)を使用しようとしていますが、方法がわかりません...それに加えて、Web.configなどにコードを追加する必要があると誰かが書いているのを見ました。それ....

助けてくれてありがとう。

編集:コードを編集し、次の行を入力します:

<%@ Import Namespace="System.Web.Mail" %>

asp.netページの上部にありますが、次のエラーが発生します:

パーサーエラーメッセージ:「@」文字の後にスペースまたは改行が見つかりました。コードブロックの先頭では、有効な識別子、キーワード、コメント、「(」、および「{」のみが有効であり、「@」の直後にスペースを入れずに使用する必要があります。

誰かが私のために正確なコードを配置できますか?

4

2 に答える 2

0

まず、System.Web.Mail名前空間をインポートする必要があります。

<%@ Import Namespace="System.Web.Mail" %>

メッセージの送信は、、、、およびのSmtpMail.Send()引数を使用してsender呼び出すことです。たとえば、C#で次のようなメールを送信します。recipientsubjectbody

string from = "sender@example.com";
 string to = "recipient@example.com";
 string subject = "Hi!";
 string body = "How are you?";
 SmtpMail.SmtpServer = "mail.example.com";
 SmtpMail.Send(from, to, subject, body);

SmtpMail.SmtpServerメッセージの配信に使用するメールサーバーを指定できます。

ここからのコンテンツ

于 2012-12-03T10:28:46.793 に答える
0

私はそれに対する解決策を見つけました

私のコードにこれを追加すると、メールが正常に送信されました。

 if(isCustomer == "yes")
               {

                  db.Execute(insertQuery,msg,id);
                  db.Execute(deleteQuery,id);
               }

               else
               {
                   WebMail.SmtpServer = "smtp.gmail.com";
                   WebMail.EnableSsl = true;
                   WebMail.SmtpPort = 587;//25
                   WebMail.UserName = "my gmail user name";
                   WebMail.Password = "my gmail password";
                   WebMail.From = "my address of email";
                   // Send email
                   WebMail.Send(
                    to: email,
                    subject: "Message from "some name of site" - Site",
                    body: msg);

                    db.Execute(deleteQuery,id);    

                }
于 2012-12-06T10:52:54.163 に答える