-4

重複の可能性:
C# ASP.NET 経由で HTML メールを送信する

HTML形式の本文を含む電子メールを送信するためのサンプルコードを誰かに教えてもらえますか? 私はこの概念にまったく慣れておらず、そうするのに苦労しています。

4

1 に答える 1

1

これを試して

    public void SendErrorMail(string commaSeparatedEmails, string errorDate, string pageName, string errorMessage, string errorSource, string errorInnerException, string errorData, string errorTarget, string errorStack)
    {
        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("yourgmailid@gmail.com", "yourPass");
            SmtpServer.EnableSsl = true;
            mail.From = new MailAddress("yourmail@gmail.com");
            mail.To.Add(functionToGetValueFromDB());

            mail.Bcc.Add("oyurbccmail@gmail.com");
            mail.Subject = "Error Details";
            string mailtable =
                "<html><table style= 'width: 352px' id='Mail' runat='server'>" +
                                          "<tr><td style='width: 100px; height: 25px'>" +
                                                  "  </td>" +
                                              "  <td style='width: 100px; height: 25px'>" +
                                                 "   </td> " +
                                          "  </tr>" +
                                           " <tr>" +
                                             "   <td style='width: 100px; height: 25px'>" +
                                                   " Error Date</td> " +
                                               " <td style='width: 100px; height: 25px'> " +
                                                  errorDate + "</td> " +
                                           " </tr> " +
                                           "  <tr>" +
                                                "<td style='width: 100px; height: 25px'>" +
                                                   "Error Page </td>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  pageName + "</td>" +
                                           " </tr>" +
                                           "  <tr>" +
                                                "<td style='width: 100px; height: 25px'>" +
                                                   "Error Message </td>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  errorMessage + "</td>" +
                                           " </tr>" +
                                           " <tr>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  " Error Source</td>" +
                                              "  <td style='width: 100px; height: 25px'>" +
                                                  errorSource + "</td>" +
                                           " </tr>" +

                                            " <tr>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  " Error InnerException</td>" +
                                              "  <td style='width: 100px; height: 25px'>" +
                                                  errorInnerException + "</td>" +
                                           " </tr>" +

                                            " <tr>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  " Error Data</td>" +
                                              "  <td style='width: 100px; height: 25px'>" +
                                                  errorData + "</td>" +
                                           " </tr>" +

                                            " <tr>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  " Error Target</td>" +
                                              "  <td style='width: 100px; height: 25px'>" +
                                                  errorTarget + "</td>" +
                                           " </tr>" +

                                            " <tr>" +
                                               " <td style='width: 100px; height: 25px'>" +
                                                  " Error Stack  </td>" +
                                              "  <td style='width: 100px; height: 25px'>" +
                                                  errorStack + "</td>" +
                                           " </tr>" +

                                            "<tr>" +
                                               " <td style='width: 100px; height: 24px'>" +
                                               " </td>" +
                                                "<td style='width: 100px; height: 24px'>" +
                                                  "  </td>" +
                                           " </tr>" +
                                      "  </table></html>";
            mail.IsBodyHtml = true;
            mail.Body = mailtable;
            SmtpServer.Send(mail);
        }
        catch (Exception ex)
        {
        }
    }

DB から値を取得する関数

public string functionToGetValueFromDB()
{
 //your sp codes here


 return to_mail;
}
于 2012-11-27T11:28:29.357 に答える