ToString()导致asp.net格式的问题 [英] ToString() Causes problem in asp.net form

查看:75
本文介绍了ToString()导致asp.net格式的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个包含许多字段的表单,我希望将其作为表单发送的电子邮件中的邮件正文。出于某种原因,这给了我一些问题。

我尝试了几种不同的方法来"聚集"。电子邮件的字段无济于事。我以为我已经解决了,但是当我在下面包含msg1.Body行时,我的电子邮件无法发送。如果我删除它,电子邮件发送就好了 - 但是我没有收到消息正文中的任何内容。 (注意:为简洁起见,我只包含了2个字段)


I am working on a form with numerous fields that I want include as the body of the message in the email sent by the form.  For some reason this has been giving me problems.

I have tried several different methods to "gather" the fields for the email, to no avail.  I thought I had it solved, but when I include the msg1.Body line below, my email fails to send.  If I remove it, the email sends just fine - however I do not get anything in the body of the message. (note: I only included 2 of the fields for brevity's sake)


msg1.From = Email.Text;
  	msg1.To = tbTo.Value;
  	msg1.Subject = tbSubject.Value;
  	msg1.Body = sb.ToString();
  	msg1.Priority = MailPriority.Normal;
  	SmtpMail.SmtpServer = "relay-hosting.secureserver.net";


完整代码如下所示:


The full code looks like this:

<script runat="server">
private void btnSend_Click(System.Object sender, System.EventArgs e) 
{
  //Creates the message
  StringBuilder sb = new StringBuilder();	
  MailMessage msg1 = new MailMessage();
  
 
  sb.Append("Parent1 First Name: " + Parent1_Fname + "\n");
  sb.Append("Parent1 Last Name: " + Parent1_Lname + "\n");
 
  
  //Sets the from, to, subject, etc...
  	msg1.From = Email.Text;
  	msg1.To = tbTo.Value;
  	msg1.Subject = tbSubject.Value;
  	msg1.Body = sb.ToString();
  	msg1.Priority = MailPriority.Normal;
  	SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
  
	msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","relay-hosting.secureserver.net");
	msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
	msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);
	msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
		  
 
  try
  {
    SmtpMail.Send(msg1);
    Response.Redirect("mbrform_thx.aspx");

  }
  catch
  {
    lblStatus.Text = "Error sending email";
  }
}
</script>


我有一个带有电子邮件服务器信息的web.config。最后一点。我正在使用<%@ Import Namespace =" System.Web.Mail" %GT;而不是System.Net.Mail,因为我发现后者我有更多/更糟的问题。

任何人都有想法吗?

And I have a web.config with the email server information.  One last note.  I am using <%@ Import Namespace="System.Web.Mail" %>  instead of System.Net.Mail because I found with the latter I had significantly more/worse problems.

Anyone have ideas here? 

推荐答案

我认为你可能会在C#编程论坛上得到更快。

我还没有很长一段时间通过代码发送任何电子邮件然后它使用VB.Net。但是,由于您收到了一条错误消息,我猜这个而不仅仅是一个换行符,我认为\ n表示,尝试一个\\\\ n,我相信这是一个马车返回和换行。

I think you would probably get a quicker in a C# programming forum.

I haven't sent any email via code in a long time and then it was using VB.Net.  However, being that you are receiving an error message where you say, I would guess that instead of just a line feed, which I think \n indicates, try a \r\n, which, I believe, is a carriage return and a line feed.


这篇关于ToString()导致asp.net格式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆