Showing posts with label received. Show all posts
Showing posts with label received. Show all posts

Monday, March 26, 2012

System.Net.Mail & sending emails with line breaks

Hi,

When a client sends an email via a web form (text entered in a asp:TextBox server control), the email received has no line breaks, and it is displayed in one line. This has bad impact on email readability... How can one overcome this probelm?

Thank you,

Alon

If you are sending mail text in simple text format then you have to use System.Environment.NewLine to move rest text in next line.

SmtpMail.SmtpServer = "1.0.0.127";
MailMessage mm = new MailMessage();
mm.From = "bill@.microsoft.com";
mm.To = "job@.apple.com";
mm.Subject = "";
mm.Body = "line 1" + System.Environment.NewLine + "line 2";


Hi,

Thank you for your reply.

I forgot to metion that the mail is sent in HTML format:

mailMessage.IsBodyHtml =true;

Am I supposed to parse the user's message (the text in the TextBox control), chck for CRLF (or is it \n) and replace it with System.Environment.NewLine? Isn't there some standard way to send the email, as i is in the text box (multiline text box. It looks like a text area)?

Thank you,

Alon


Here is the modified code for HTML formated body

mm.Body = "line 1" + "<br>" + "line 2";

Rest of the code will remain same.


But how can I know where line1 ends and line2 starts? All I have is a string I get form TextBox.Text. From this string I cannot deduce where did the user hit return - it's a "flat" string.

A word about he context of this: this web form is a "Contact Us" page. The TextBox is a multiline text box, which serves as a free text input field.

Thank you,

Alon


As what Firoz said, you have to use the "<br />"

You will use the following code to replace each line in your textbox to break

Replace(textbox1.text, vbCrLf,"<br />")

HTH
Regards


Oooops, now I understand. It works. I thank the both of you.

Alon

Thursday, March 22, 2012

System.NullReferenceException: Object reference not set to an instance of an object.

Hi, the following code received run-time error (NullReferenceException), and I don't know how to troubleshoot it :(
under Page_Load at Default.aspx:
loginBox.LoginAuthenticated += new LoginAuthenticatedEventHandler(Succeeded)
under my LoginBox.ascx.cs, I setup the object like the followings:
public delegate void LoginAuthenticatedEventHandler(object sender, LoginAuthenticatedEventArgs e);
public event LoginAuthenticatedEventHandler LoginAuthenticated;
public class LoginAuthenticatedEventArgs : EventArgs
{
public int UsrID;
}//end class LoginAuthenticatedEventArgs

under my Page_Load of my LoginBox.ascx.cs, I load my object like this:
if (LoginAuthenticated != null)
{
LoginAuthenticatedEventArgs eventInfo = new LoginAuthenticatedEventArgs();
eventInfo.UsrID = Int32.Parse(txtUser.Text);
LoginAuthenticated(Page, eventInfo);
}//end if (LoginAuthenticated != null)

I thought I had the object reference to the correct place, what else am I missing?
TIA
..resoloved: http://forums.asp.net/1089126/ShowPost.aspx

System.NullReferenceException: Object variable or With block varia

Hello -

I don't know if it's possible or not, but I am trying to bind data from a
Sql Server DB to the header in a datalist. I received the above error
message.

First, is it possible to bind data from a DB to the header and if so, what
could be causing the error message?

Alternatively, can you only put text in the header of a datalist?
--
SandySandy,
You didn't provide any code many it very difficult to imagine what the error
is...

Yyou can't bind data to a header in the typical databinding sense.
Information is bound row-by-row to the individual items...There's no row
assigned to the header...you can set values of the header progamatically
however...

myGrid.Columns(0).HeaderText =
myDataSet.Tables(0).Rows(0)("Blah").ToString()

or something similar...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sandy" <Sandy@.discussions.microsoft.com> wrote in message
news:BBD0DEED-455D-473C-8D00-8D969825BCF6@.microsoft.com...
> Hello -
> I don't know if it's possible or not, but I am trying to bind data from a
> Sql Server DB to the header in a datalist. I received the above error
> message.
> First, is it possible to bind data from a DB to the header and if so, what
> could be causing the error message?
> Alternatively, can you only put text in the header of a datalist?
> --
> Sandy
Thanks, Karl!

"Karl Seguin" wrote:

> Sandy,
> You didn't provide any code many it very difficult to imagine what the error
> is...
> Yyou can't bind data to a header in the typical databinding sense.
> Information is bound row-by-row to the individual items...There's no row
> assigned to the header...you can set values of the header progamatically
> however...
> myGrid.Columns(0).HeaderText =
> myDataSet.Tables(0).Rows(0)("Blah").ToString()
> or something similar...
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Sandy" <Sandy@.discussions.microsoft.com> wrote in message
> news:BBD0DEED-455D-473C-8D00-8D969825BCF6@.microsoft.com...
> > Hello -
> > I don't know if it's possible or not, but I am trying to bind data from a
> > Sql Server DB to the header in a datalist. I received the above error
> > message.
> > First, is it possible to bind data from a DB to the header and if so, what
> > could be causing the error message?
> > Alternatively, can you only put text in the header of a datalist?
> > --
> > Sandy
>

System.NullReferenceException: Object variable or With block varia

Hello -
I don't know if it's possible or not, but I am trying to bind data from a
Sql Server DB to the header in a datalist. I received the above error
message.
First, is it possible to bind data from a DB to the header and if so, what
could be causing the error message?
Alternatively, can you only put text in the header of a datalist?
--
SandySandy,
You didn't provide any code many it very difficult to imagine what the error
is...
Yyou can't bind data to a header in the typical databinding sense.
Information is bound row-by-row to the individual items...There's no row
assigned to the header...you can set values of the header progamatically
however...
myGrid.Columns(0).HeaderText =
myDataSet.Tables(0).Rows(0)("Blah").ToString()
or something similar...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Sandy" <Sandy@.discussions.microsoft.com> wrote in message
news:BBD0DEED-455D-473C-8D00-8D969825BCF6@.microsoft.com...
> Hello -
> I don't know if it's possible or not, but I am trying to bind data from a
> Sql Server DB to the header in a datalist. I received the above error
> message.
> First, is it possible to bind data from a DB to the header and if so, what
> could be causing the error message?
> Alternatively, can you only put text in the header of a datalist?
> --
> Sandy