G
Guest
I'm working on a minor bug from an open source bug tracking system
(bugtracket.net). It's a great app, but I don't want to bother the
creator any more than I have to, so I thought I'd pose the question
here.
The problem is with an email that gets sent from the system. In a
nutshell, it's an HTML format email that is choking on the string that
is returned form this function that is added to the email's body:
string get_bug_text(int bugid)
{
// Get bug html
DataRow bug_dr = get_bug_datarow(bugid);
// Create a fake response and let the code
// write the html to that response
System.IO.StringWriter writer = new System.IO.StringWriter();
HttpResponse my_response = new HttpResponse(writer);
print_bug(my_response, bug_dr);
return writer.ToString();
}
(the print_bug function is at the bottom of thie message.)
I'm sure it's something in the string becasue i can set the body of
the email to something else and it is sent fine. And I've seen the
actual html that comes back and it appears to be ok.
THe error is:
The message could not be sent to the SMTP server. The transport error
code was 0x800ccc6a.
And when I look at the actual trace, it's the 'can't access
CDO.message' error. I can post it if someone would find it helpful.
Thanks for any insights!
Rich
///////////////////////////////////////////////////////////////////////
void print_bug (HttpResponse Response, DataRow dr)
{
Response.Write ("<style>");
Response.WriteFile(Server.MapPath("./") + "btnet_base.css");
Response.Write ("\n");
Response.WriteFile(Server.MapPath("./") + "btnet_custom.css");
Response.Write ("</style>");
Response.Write ("<body style=background:white>");
Response.Write (""
+ Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug"))
+ " ID: <a href="
+ Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
+ "edit_bug.aspx?id="
+ dr["id"].ToString()
+ ">"
+ dr["id"].ToString()
+ "</a><br>");
Response.Write ("Short desc: <a href="
+ Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
+ "edit_bug.aspx?id="
+ dr["id"].ToString()
+ ">"
+ HttpUtility.HtmlEncode((string)dr["short_desc"])
+ "</a><p>");
Response.Write ("<table border=1 cellpadding=3 cellspacing=0>");
Response.Write ("<tr><td>Last changed by<td>" + dr["last_updated_user"] +
" ");
Response.Write ("<tr><td>Reported By<td>" + dr["reporter"] + " ");
Response.Write ("<tr><td>Reported On<td>" +
Util.format_db_date(dr["reported_date"]) + " ");
Response.Write ("<tr><td>Project<td>" + dr["current_project"] + " ");
Response.Write ("<tr><td>Category<td>" + dr["category_name"] + " ");
Response.Write ("<tr><td>Priority<td>" + dr["priority_name"] + " ");
Response.Write ("<tr><td>Assigned<td>" + dr["assigned_to_username"] + " ");
Response.Write ("<tr><td>Status<td>" + dr["status_name"] + " ");
if (Util.get_setting("ShowUserDefinedBugAttribute","1") == "1")
{
Response.Write ("<tr><td>"
+ Util.get_setting("UserDefinedBugAttributeName","YourAttribute")
+ "<td>"
+ dr["udf_name"] + " ");
}
// Get custom column info (There's an inefficiency here - we just did this
// same call in get_bug_datarow...)
DataSet ds_custom_cols = Util.get_custom_columns(dbutil);
// Show custom columns
foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
{
Response.Write ("<tr><td>");
Response.Write (drcc["name"]);
Response.Write ("<td>");
if ((string)drcc["datatype"] == "datetime")
{
object dt = dr[(string)drcc["name"]];
Response.Write (Util.format_db_date(dt));
}
else
{
string s = Convert.ToString(dr[(string)drcc["name"]]);
s = HttpUtility.HtmlEncode(s);
s = s.Replace("\n","<br>");
s = s.Replace(" "," ");
s = s.Replace("\t"," ");
Response.Write (s);
}
Response.Write (" ");
}
// create project custom dropdowns
if ((int)dr["project"] != 0)
{
sql = @"select
isnull(pj_enable_custom_dropdown1,0) [pj_enable_custom_dropdown1],
isnull(pj_enable_custom_dropdown2,0) [pj_enable_custom_dropdown2],
isnull(pj_enable_custom_dropdown3,0) [pj_enable_custom_dropdown3],
isnull(pj_custom_dropdown_label1,'') [pj_custom_dropdown_label1],
isnull(pj_custom_dropdown_label2,'') [pj_custom_dropdown_label2],
isnull(pj_custom_dropdown_label3,'') [pj_custom_dropdown_label3]
from projects where pj_id = $pj";
sql = sql.Replace("$pj", Convert.ToString((int)dr["project"]));
DataRow project_dr = dbutil.get_datarow(sql);
for (int i = 1; i < 4; i++)
{
if ((int)project_dr["pj_enable_custom_dropdown" + Convert.ToString(i)] ==
1)
{
Response.Write ("<tr><td>");
Response.Write (project_dr["pj_custom_dropdown_label" +
Convert.ToString(i)]);
Response.Write ("<td>");
Response.Write (dr["bg_project_custom_dropdown_value" +
Convert.ToString(i)]);
Response.Write (" ");
}
}
}
Response.Write("</table><p>");
// Show comments
if (Util.get_setting("ShowHistoryWithComments", "0") == "1")
{
Response.Write ("Comments and Change History");
}
else
{
Response.Write ("Comments");
}
if (Util.get_setting("ShowHistoryWithComments", "0") == "1")
{
sql = @"select
bc_comment,
isnull(us_username,'') [us_username],
isnull(us_email,'') [us_email],
bc_date,
bc_id,
bc_type,
isnull(bc_email_from,'') [bc_email_from],
isnull(bc_email_to,'') [bc_email_to]
from bug_comments
left outer join users on us_id = bc_user
where bc_bug = $id
order by bc_date " + Util.get_setting("CommentSortOrder","desc");
}
else
{
sql = @"select
bc_comment,
isnull(us_username,'') [us_username],
isnull(us_email,'') [us_email],
bc_date,
bc_id,
bc_type,
isnull(bc_email_from,'') [bc_email_from],
isnull(bc_email_to,'') [bc_email_to]
from bug_comments
left outer join users on us_id = bc_user
where bc_bug = $id
and bc_type <> 'update'
order by bc_date " + Util.get_setting("CommentSortOrder","desc");
}
bool show_initial_comment = false;
if (Util.get_setting("CommentSortOrder","desc") == "desc"
&& Util.get_setting("ShowInitialCommentFirst", "1") == "1")
{
show_initial_comment = true;
// get the initial comment again in a seperate dataset
sql += @"
select top 1
bc_comment,
isnull(us_username,'') [us_username],
isnull(us_email,'') [us_email],
bc_date,
bc_id
from bug_comments
left outer join users on us_id = bc_user
where bc_bug = $id
and bc_type = 'comment'
order by bc_date";
}
sql = sql.Replace("$id", dr["id"].ToString());
DataSet ds_comments = dbutil.get_dataset(sql);
Response.Write ("<p><table border=1 cellspacing=0 cellpadding=4>");
// save this so we can avoid showing the initial comment twice
int initial_comment_id = -1;
if (show_initial_comment)
{
// save the id of the initial comment
foreach (DataRow dr_comments_initial in ds_comments.Tables[1].Rows)
{
initial_comment_id = (int) dr_comments_initial["bc_id"];
Response.Write ("<tr><td><table width=100% ><tr><td align=left>");
Response.Write ("<span>Initial comment posted by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments_initial["us_email"], (string)
dr_comments_initial["us_username"]));
Response.Write (" on ");
Response.Write (Util.format_db_date(dr_comments_initial["bc_date"]));
Response.Write ("</span></td>");
Response.Write ("</td></tr></table><table border=0><tr><td>");
string s = (string) dr_comments_initial["bc_comment"];
s = Util.format_comment(s);
Response.Write (s);
Response.Write ("</td></tr></table></td></tr>");
}
}
foreach (DataRow dr_comments in ds_comments.Tables[0].Rows)
{
// don't show "initial comment" twice
if ((int) dr_comments["bc_id"] == initial_comment_id)
{
break;
}
Response.Write ("<tr><td>");
if ((string)dr_comments["bc_type"] == "update") // update
{
// posted by
Response.Write ("<span>changed by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments["us_email"], (string)
dr_comments["us_username"]));
Response.Write (" on ");
Response.Write (Util.format_db_date(dr_comments["bc_date"]));
Response.Write ("</span>");
}
else
{
if ((string)dr_comments["bc_type"] == "sent" ) // sent email
{
Response.Write ("<span>email sent to ");
Response.Write (Util.format_email_to(id,
(string)dr_comments["bc_email_to"]));
Response.Write (" by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments["us_email"], (string)
dr_comments["us_username"]));
}
else if ((string)dr_comments["bc_type"] == "received" ) // received email
{
Response.Write ("<span>email received from ");
Response.Write (Util.format_email_from(
(int)dr_comments["bc_id"],
(string)dr_comments["bc_email_from"]));
}
else
{
Response.Write ("<span>comment posted by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments["us_email"], (string)
dr_comments["us_username"]));
}
Response.Write (" on ");
Response.Write (Util.format_db_date(dr_comments["bc_date"]));
Response.Write ("</span>");
}
// the text itself
Response.Write ("<br><br>");
string s = (string) dr_comments["bc_comment"];
s = Util.format_comment(s);
Response.Write (s);
Response.Write ("</td></tr>");
}
Response.Write ("</table>");
if (Util.get_setting("PrintHistory", "1") != "0"
&& Util.get_setting("ShowHistoryWithComments", "0") == "0")
{
Response.Write ("<p>Change History<p><table border=1 cellspacing=0
cellpadding=3>");
sql = @"select
bc_comment [change],
us_username [user],
bc_date [date]
from bug_comments
inner join users on bc_user = us_id
where bc_bug = $id
and bc_type = 'update'
order by bc_date " + Util.get_setting("CommentSortOrder","desc");
sql = sql.Replace("$id", dr["id"].ToString());
DataSet ds3 = dbutil.get_dataset(sql);
foreach (DataRow dr3 in ds3.Tables[0].Rows)
{
Response.Write ("<tr><td>");
Response.Write (dr3["change"]);
Response.Write ("<td>");
Response.Write (dr3["user"]);
Response.Write ("<td>");
Response.Write (Util.format_db_date(dr3["date"]));
Response.Write ("</td></tr>");
}
Response.Write ("</table>");
}
Response.Write ("<div class=align><table
border=0><tr><td></table></div></body>");
}
</script>
(bugtracket.net). It's a great app, but I don't want to bother the
creator any more than I have to, so I thought I'd pose the question
here.
The problem is with an email that gets sent from the system. In a
nutshell, it's an HTML format email that is choking on the string that
is returned form this function that is added to the email's body:
string get_bug_text(int bugid)
{
// Get bug html
DataRow bug_dr = get_bug_datarow(bugid);
// Create a fake response and let the code
// write the html to that response
System.IO.StringWriter writer = new System.IO.StringWriter();
HttpResponse my_response = new HttpResponse(writer);
print_bug(my_response, bug_dr);
return writer.ToString();
}
(the print_bug function is at the bottom of thie message.)
I'm sure it's something in the string becasue i can set the body of
the email to something else and it is sent fine. And I've seen the
actual html that comes back and it appears to be ok.
THe error is:
The message could not be sent to the SMTP server. The transport error
code was 0x800ccc6a.
And when I look at the actual trace, it's the 'can't access
CDO.message' error. I can post it if someone would find it helpful.
Thanks for any insights!
Rich
///////////////////////////////////////////////////////////////////////
void print_bug (HttpResponse Response, DataRow dr)
{
Response.Write ("<style>");
Response.WriteFile(Server.MapPath("./") + "btnet_base.css");
Response.Write ("\n");
Response.WriteFile(Server.MapPath("./") + "btnet_custom.css");
Response.Write ("</style>");
Response.Write ("<body style=background:white>");
Response.Write (""
+ Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug"))
+ " ID: <a href="
+ Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
+ "edit_bug.aspx?id="
+ dr["id"].ToString()
+ ">"
+ dr["id"].ToString()
+ "</a><br>");
Response.Write ("Short desc: <a href="
+ Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
+ "edit_bug.aspx?id="
+ dr["id"].ToString()
+ ">"
+ HttpUtility.HtmlEncode((string)dr["short_desc"])
+ "</a><p>");
Response.Write ("<table border=1 cellpadding=3 cellspacing=0>");
Response.Write ("<tr><td>Last changed by<td>" + dr["last_updated_user"] +
" ");
Response.Write ("<tr><td>Reported By<td>" + dr["reporter"] + " ");
Response.Write ("<tr><td>Reported On<td>" +
Util.format_db_date(dr["reported_date"]) + " ");
Response.Write ("<tr><td>Project<td>" + dr["current_project"] + " ");
Response.Write ("<tr><td>Category<td>" + dr["category_name"] + " ");
Response.Write ("<tr><td>Priority<td>" + dr["priority_name"] + " ");
Response.Write ("<tr><td>Assigned<td>" + dr["assigned_to_username"] + " ");
Response.Write ("<tr><td>Status<td>" + dr["status_name"] + " ");
if (Util.get_setting("ShowUserDefinedBugAttribute","1") == "1")
{
Response.Write ("<tr><td>"
+ Util.get_setting("UserDefinedBugAttributeName","YourAttribute")
+ "<td>"
+ dr["udf_name"] + " ");
}
// Get custom column info (There's an inefficiency here - we just did this
// same call in get_bug_datarow...)
DataSet ds_custom_cols = Util.get_custom_columns(dbutil);
// Show custom columns
foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
{
Response.Write ("<tr><td>");
Response.Write (drcc["name"]);
Response.Write ("<td>");
if ((string)drcc["datatype"] == "datetime")
{
object dt = dr[(string)drcc["name"]];
Response.Write (Util.format_db_date(dt));
}
else
{
string s = Convert.ToString(dr[(string)drcc["name"]]);
s = HttpUtility.HtmlEncode(s);
s = s.Replace("\n","<br>");
s = s.Replace(" "," ");
s = s.Replace("\t"," ");
Response.Write (s);
}
Response.Write (" ");
}
// create project custom dropdowns
if ((int)dr["project"] != 0)
{
sql = @"select
isnull(pj_enable_custom_dropdown1,0) [pj_enable_custom_dropdown1],
isnull(pj_enable_custom_dropdown2,0) [pj_enable_custom_dropdown2],
isnull(pj_enable_custom_dropdown3,0) [pj_enable_custom_dropdown3],
isnull(pj_custom_dropdown_label1,'') [pj_custom_dropdown_label1],
isnull(pj_custom_dropdown_label2,'') [pj_custom_dropdown_label2],
isnull(pj_custom_dropdown_label3,'') [pj_custom_dropdown_label3]
from projects where pj_id = $pj";
sql = sql.Replace("$pj", Convert.ToString((int)dr["project"]));
DataRow project_dr = dbutil.get_datarow(sql);
for (int i = 1; i < 4; i++)
{
if ((int)project_dr["pj_enable_custom_dropdown" + Convert.ToString(i)] ==
1)
{
Response.Write ("<tr><td>");
Response.Write (project_dr["pj_custom_dropdown_label" +
Convert.ToString(i)]);
Response.Write ("<td>");
Response.Write (dr["bg_project_custom_dropdown_value" +
Convert.ToString(i)]);
Response.Write (" ");
}
}
}
Response.Write("</table><p>");
// Show comments
if (Util.get_setting("ShowHistoryWithComments", "0") == "1")
{
Response.Write ("Comments and Change History");
}
else
{
Response.Write ("Comments");
}
if (Util.get_setting("ShowHistoryWithComments", "0") == "1")
{
sql = @"select
bc_comment,
isnull(us_username,'') [us_username],
isnull(us_email,'') [us_email],
bc_date,
bc_id,
bc_type,
isnull(bc_email_from,'') [bc_email_from],
isnull(bc_email_to,'') [bc_email_to]
from bug_comments
left outer join users on us_id = bc_user
where bc_bug = $id
order by bc_date " + Util.get_setting("CommentSortOrder","desc");
}
else
{
sql = @"select
bc_comment,
isnull(us_username,'') [us_username],
isnull(us_email,'') [us_email],
bc_date,
bc_id,
bc_type,
isnull(bc_email_from,'') [bc_email_from],
isnull(bc_email_to,'') [bc_email_to]
from bug_comments
left outer join users on us_id = bc_user
where bc_bug = $id
and bc_type <> 'update'
order by bc_date " + Util.get_setting("CommentSortOrder","desc");
}
bool show_initial_comment = false;
if (Util.get_setting("CommentSortOrder","desc") == "desc"
&& Util.get_setting("ShowInitialCommentFirst", "1") == "1")
{
show_initial_comment = true;
// get the initial comment again in a seperate dataset
sql += @"
select top 1
bc_comment,
isnull(us_username,'') [us_username],
isnull(us_email,'') [us_email],
bc_date,
bc_id
from bug_comments
left outer join users on us_id = bc_user
where bc_bug = $id
and bc_type = 'comment'
order by bc_date";
}
sql = sql.Replace("$id", dr["id"].ToString());
DataSet ds_comments = dbutil.get_dataset(sql);
Response.Write ("<p><table border=1 cellspacing=0 cellpadding=4>");
// save this so we can avoid showing the initial comment twice
int initial_comment_id = -1;
if (show_initial_comment)
{
// save the id of the initial comment
foreach (DataRow dr_comments_initial in ds_comments.Tables[1].Rows)
{
initial_comment_id = (int) dr_comments_initial["bc_id"];
Response.Write ("<tr><td><table width=100% ><tr><td align=left>");
Response.Write ("<span>Initial comment posted by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments_initial["us_email"], (string)
dr_comments_initial["us_username"]));
Response.Write (" on ");
Response.Write (Util.format_db_date(dr_comments_initial["bc_date"]));
Response.Write ("</span></td>");
Response.Write ("</td></tr></table><table border=0><tr><td>");
string s = (string) dr_comments_initial["bc_comment"];
s = Util.format_comment(s);
Response.Write (s);
Response.Write ("</td></tr></table></td></tr>");
}
}
foreach (DataRow dr_comments in ds_comments.Tables[0].Rows)
{
// don't show "initial comment" twice
if ((int) dr_comments["bc_id"] == initial_comment_id)
{
break;
}
Response.Write ("<tr><td>");
if ((string)dr_comments["bc_type"] == "update") // update
{
// posted by
Response.Write ("<span>changed by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments["us_email"], (string)
dr_comments["us_username"]));
Response.Write (" on ");
Response.Write (Util.format_db_date(dr_comments["bc_date"]));
Response.Write ("</span>");
}
else
{
if ((string)dr_comments["bc_type"] == "sent" ) // sent email
{
Response.Write ("<span>email sent to ");
Response.Write (Util.format_email_to(id,
(string)dr_comments["bc_email_to"]));
Response.Write (" by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments["us_email"], (string)
dr_comments["us_username"]));
}
else if ((string)dr_comments["bc_type"] == "received" ) // received email
{
Response.Write ("<span>email received from ");
Response.Write (Util.format_email_from(
(int)dr_comments["bc_id"],
(string)dr_comments["bc_email_from"]));
}
else
{
Response.Write ("<span>comment posted by ");
Response.Write (Util.format_email_username(
id, (string) dr_comments["us_email"], (string)
dr_comments["us_username"]));
}
Response.Write (" on ");
Response.Write (Util.format_db_date(dr_comments["bc_date"]));
Response.Write ("</span>");
}
// the text itself
Response.Write ("<br><br>");
string s = (string) dr_comments["bc_comment"];
s = Util.format_comment(s);
Response.Write (s);
Response.Write ("</td></tr>");
}
Response.Write ("</table>");
if (Util.get_setting("PrintHistory", "1") != "0"
&& Util.get_setting("ShowHistoryWithComments", "0") == "0")
{
Response.Write ("<p>Change History<p><table border=1 cellspacing=0
cellpadding=3>");
sql = @"select
bc_comment [change],
us_username [user],
bc_date [date]
from bug_comments
inner join users on bc_user = us_id
where bc_bug = $id
and bc_type = 'update'
order by bc_date " + Util.get_setting("CommentSortOrder","desc");
sql = sql.Replace("$id", dr["id"].ToString());
DataSet ds3 = dbutil.get_dataset(sql);
foreach (DataRow dr3 in ds3.Tables[0].Rows)
{
Response.Write ("<tr><td>");
Response.Write (dr3["change"]);
Response.Write ("<td>");
Response.Write (dr3["user"]);
Response.Write ("<td>");
Response.Write (Util.format_db_date(dr3["date"]));
Response.Write ("</td></tr>");
}
Response.Write ("</table>");
}
Response.Write ("<div class=align><table
border=0><tr><td></table></div></body>");
}
</script>