email from a .net form

Discussion in 'ASP.NET / ASP.NET Core' started by mlawrence, Mar 17, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have a form that is suppose to send me an email upon submission. It works just fine on my machine so I am probably missing something silly here. Here is the code;

    MailMessage mailmessage = new MailMessage();

    mailmessage.To = "[email protected]";
    mailmessage.From = txtName.Text;
    mailmessage.Subject = "New entry in the Guest book";
    mailmessage.BodyFormat = MailFormat.Text;
    mailmessage.Body = tboxcomments.Text;

    SmtpMail.SmtpServer = "localhost";
    SmtpMail.Send(mailmessage);

    Any help would be appreciated, thanks.
     
  2. Yeah, I saw the same example on Google and I could not get that to work. I tried;
    mailmessage.Body = "\r\n" + tboxcomments.Text + "\r\n";
    and
    mailmessage.Body = Environment.NewLine + tboxcomments.Text + Environment.NewLine;
    and neither worked. Thanks for the input anyway.
     
  3. The two examples you listed won't solve the problem. You need to replace ALL line-feeds with carriage-return line-feeds, not just add the carriage-return at the start and end of your message.

    tboxcomments.Text probably contains some line feeds. Use the function replace() to remove or replace them.
     
  4. mlawrence

    Thanks! You taught me a lesson, I have alway used propriety classes to send email and not .net objects so I was a little unsure. You are absolutey correct in what you were saying.

    For those of you that might run into this in the future this is the final code that works. As always replace the To and the From;

    MailMessage mailmessage = new MailMessage();

    mailmessage.To = "[email protected]";
    mailmessage.From = "[email protected]";//txtName.Text;
    mailmessage.Subject = "New entry in the Guest book";
    mailmessage.BodyFormat = MailFormat.Text;
    string comments = tboxcomments.Text;
    comments.Replace("\n", "\r\n");
    mailmessage.Body = comments;

    SmtpMail.SmtpServer = "localhost";
    SmtpMail.Send(mailmessage);
    Thanks again.
     
  5. hi, I am not a programmer and totally new to asp..

    I am hoping you could simplify some of what you guys have been talking about and offer some suggestions..

    I have a site I am about to upload, a membership site, initial trial entry...so i need to set up total protection for the site after the first page (200+ pages), find a way to do usernames and passwords, have those link into paypal who the payments will be through, and overcome fp2003 extension problems I hear in this area..

    Your input would be greatly appreciated
     
  6. oopps, this was not the forum I clicked on to reply to...sorry
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page