メールを1つのメッセージとして送信することに問題があります。このコードはデータベースからすべてのコンテンツを読み取りますが、メッセージを1つとして電子メールで送信しません。データベース内の行またはデータの量によって繰り返し送信されます。最初にコンテンツをバインドして、1つとして電子メールに送信するにはどうすればよいですか?
int Quantity = 0;
string JobName;
string OrderType;
DateTime DueDate;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
string cmdText = "SELECT * FROM Shopping_Cart WHERE UID=@UIDD";
SqlCommand cmd = new SqlCommand(cmdText, con);
cmd.Parameters.AddWithValue("@UIDD", hfUserID.Value);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] {
new DataColumn("QUANTITY", typeof(int)),
new DataColumn("JOB NAME", typeof(string)),
new DataColumn("ORDER TYPE", typeof(string)),
new DataColumn("DUE DATE", typeof(DateTime))});
//===== Execute Query.
SqlDataReader dr = cmd.ExecuteReader();
if (Session["UID"] != null)
{
while (dr.Read())
{
Quantity = dr.GetInt32(4);
JobName = dr.GetString(10);
OrderType = dr.GetString(17);
DueDate = dr.GetDateTime(9);
dt.Rows.Add(Quantity, JobName, OrderType, DueDate);
}
StringBuilder YourTable = new StringBuilder();
YourTable.Append("Thank you for choosing Junand's Labels Inc. Your order will be evaluated by the manager with the maximum of (3 days). Please wait for the confirmation of the manager in your email whether your order will be acceptable or not. The price will be announced once the order has been accepted. ");
YourTable.Append("<br>");
YourTable.Append("<br>");
YourTable.Append("Order Review");
YourTable.Append("<table border = '1'>");
YourTable.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
YourTable.Append("<th style = 'background-color: #0bd2d1;color:#ffffff'>");
YourTable.Append(column.ColumnName);
YourTable.Append("</th>");
}
YourTable.Append("</tr>");
foreach (DataRow row in dt.Rows)
{
YourTable.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
YourTable.Append("<td>");
YourTable.Append(row[column]);
YourTable.Append("</td>");
}
YourTable.Append("</tr>");
MailMessage message = new MailMessage();
message.Body += YourTable;
message.To.Add(Session["Email"].ToString());
message.From = new MailAddress("[email protected]");
message.Subject = "View your Orders";
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.Send(message);
}
}
メールの送信を移動します
client.Send(message);
の外
foreach (DataRow row in dt.Rows)
ループ。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加