Sending an Email with -- problem with strings and body of the email.


I am trying to email the contents of a contact form such that the email body looks like this:

Last name: Smith
First name: John
Comment: Test comment.

I am using the MailMessage object.

I am storing the textbox values in strings:

//assign values from form to variables
  string first = textboxFirst.Text;
  string last = textboxLast.Text;
  string comment = textboxComment.Text;

and then combining the strings into one string for my MaiMessage.Body property.

  //create message body from textbox variables
    string message = "Last Name: "  + last + "First Name: " + first + "Comment: " + comment;

Which gives me the message as     LastName: last FirstName: first Comment: comment.

How do I manage is so that it looks like this:

Last name: Smith
First name: John
Comment: Test comment.

I've tried escaping characters and I've tried adding to the string, but I really want the body of the email to have the fields on separate lines.

Any advice is much appreciated.




2/23/2007 11:42:04 PM 91979 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 29

use a stringbuilder to create the body text.

Dim body as new StringBuilder

body.AppendFormat("Last name: {0}{1}", last, Environment.NewLine)
body.AppendFormat("First name: {0}{1}", first, Environment.NewLine)
body.AppendFormat("Comment: {0}{1}", comment, Environment.NewLine)

mailmsg.Body = body.ToString
Mike Banavige

Need a site code sample in a different language? Try converting it with:
2/24/2007 1:51:42 AM
Perfect!  Thanks so much!
2/24/2007 3:53:53 AM

Similar Artilces:

Hi and thanks for your help!! I have a window that pops up to send an email to a person using the following javascript: <script type="text/javascript"> //<![CDATA[function OnClientCommandExecuting(editor, args) {var commandName = args.get_commandName(); var strEmail = document.getElementById("PersonsEmail").value;if (args.get_commandName() == "SendEmail") { var oWnd = radopen("sendemail.aspx?email=" + strEmail, "rwEmail");;args.set_cancel(true); } }   //]]> </script>   On the email ...

Sending Email through System.Net.Mail is generating errors "Failure Sending mail
hi Sending Email through System.Web.Mail is working fine but System.Net.Mail is generating errors "Failure Sending mail  i treid in all possible ways but did't  pls help in giving a solution thanks & Regards vittal Maybe you can show us some code and post the exact error mesg as well (by looking at the value in ex.tostring)?My HomePage -"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)Progress - "Never discourage anyone...who continually makes progress, no matter how slow." Plato System.Web.Ma...

Sending Email with Net.Mail (No Email, no error)
hi,i'm using the namespace to send an email from my application. when i send, the application does not fire any exception, neither does it send the email to my account.below is the code i'm using  Dim mmailMessage As New Net.Mail.MailMessage Dim mFrom As New Net.Mail.MailAddress(mailFrom) mmailMessage.From = mFrom Dim ll As String = "" mmailMessage.To.Add(ll) mmailMessage.Subject = "Talk Concerns" mmailMessage.Body = "Testing Concerns One Two" Dim ...

Sending Email with System.Net.Mail
I Wants to Send Email using System.Net.Mail without editing / Adding New Tag in web.config.How can i set Host in cs file.  Thanks & Regards,Mac try the following linkds  using System;using System.Web.Mail;using System.Data;using System.Data.SqlClient;using System.IO;using System.Configuration;/// <summary>/// Summary description for EmailClass/// </sum...

Sending Emails with System.Net.Mail
I am having problems getting my web pages to send emails using System.Net.Mail.  When my efforts failed, I downloaded a simple routine that sends an email to a hardcoded address.  Here is the code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim mail As New MailMessage() 'set the addresses mail.From = New MailAddress("") mail.To.Add("") 'set the content mail.Subject = "This is an email" mail.Body = "this is the body content...

Sending email using
 I am trying to send email using Asp .Net. I am using System.Net.Mail namespace. The code i written is below MailMessage message = new MailMessage(); message.From = new MailAddress(""); message.To.Add(new MailAddress("")); message.Subject = "Test"; message.Body = "This is a test message"; message.IsBodyHtml = false; SmtpClient mailClient = new SmtpClient("", 587); mailClient.Credentials = ne...

Sending Email with System.Net.Mail. Where is from name???
                MailMessage msg = new MailMessage();                 msg.From = "";                 msg.To = ""                 msg.Subject = "test";                 msg.Body = "test test";                 m...

Hello,I'm trying to run the following script I seen off of the web, and I can't get it to work.  I'm having problems with the implementation; no email is being sent.  I'm sure it is a valid email.  I'm not getting any exceptions thrown.  I'm also using a web server I don't have access to, so I don't know if it is a setting there?  I could contact the person, but I don't know what to suggest?  Thanks for any help on the matter.  Oh, and I assume references the localhost; I tried the localhost string and nothing s...

Unable to send emails with System.Net.Mail
I have been trying to send emails from my web site on my development computer using VWD and System.Net.Mail with no success.The code I'm using is as follows: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim mail As New MailMessage() 'set the addresses mail.From = New MailAddress("") mail.To.Add("") 'set the content mail.Subject = "This is an email" mail.Body = "this is the body content of the email....

Sending emails With C# System.Net.Mail
SmtpClient objSMTPClient = new SmtpClient();MailAddress objFromMailAddress = new MailAddress(;MailAddress objToMailAddress = new MailAddress(;MailMessage objMail = new MailMessage(objFromMailAddress, objToMailAddress); objMail.Subject = "Job Number " + txtjobNum.Text;objMail.Body = "The job " + txtjobNum + " has been submitted for backup. Please check job website for more info.";objSMTPClient.Host = "s1";objSMTPClient.Port = 25;objSMTPClient.Credentials = CredentialCache.DefaultNetworkCredentials; //should use the users current login to authentic...

HOW TO: Send email using System.Net.Mail
 Looks like they locked the thread in the FAQ section, so I'll just ask my question here. I"m using a version of the System.Net.Mail class that was posted in the FAQ section. I'm trying to use it like this:            string from = EmailTextBox.Text;            string to = ContactIdentifier.EmailAddress;            string bcc = "";            strin...

Send email using System.Net.Mail
hi to all,  while i am sending mail to gmail ,i am facing problem.but i can send mail to other smtp adress like( give advice how to send email to gmail(i didn't give any details other than  below code).thank you in advance.   protected void btnSubmit_Click(object sender, EventArgs e)        {                                     &nbs...

HOW TO: Send email using System.Net.Mail
Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email. Download C# System.Net.Mail HelperDownload VB.NET System.Net.Mail Helper Calling the function from code MailHelper.SendMailMessage("", "", "", "", "Sample Subject", "Sample body of text for mail message") MailHelper.cs using System.Net.Mail; public class MailHelper{   /// <summary>   /// Sends an mail ...

Send Email from form using
Please see code behind below. This my message is being received by only with hard coded text of subject with no body.  How do I correct my syntax so that the information is passed from form fields to email message?  The form data is being inserted into the db and redirected to .aspx page.  Just need to get data from for fields to message.  -------------------------------------------- Imports System.Net.MailPartial Class apps_contactpage Inherits System.Web.UI.PageSub Send2Mail(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs) 'create the mail...
Hi, Previously on my web app I had a contact page that would send an email to me with all the filled in values from the user.  The email would be sent with the FROM address the user put in, so when I received it I could reply back to them.  I had this working for years, and now all of a sudden it errors out.  I get the following error.  Please note I was using System.Net.Mail, but changed to a component to try and debug. I'm wondering what would cause this error to happen suddenly?  Perhaps a configuration change in IIS ?  What would be a good work aroun...

Web resources about - Sending an Email with -- problem with strings and body of the email. -

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

[...] Facebook Prevents Users From Sending Suspicious Friend Requests To Strangers, Inside Facebook [...] ...
Facebook has begun implementing new security measures to prevent friend request spamming. Some users are being shown a “This Request Can’t Be ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Emoticon and Emoji Box for iPhone -Save Emoticons,emoji,pic and images for Sending Message! 200 FREE ...
Get Emoticon and Emoji Box for iPhone -Save Emoticons,emoji,pic and images for Sending Message! 200 FREE emoticons and emojis - on the App Store. ...

Thanks for sending an iPhone4 and Sim T-Mobile but ... - Flickr - Photo Sharing!
... that's probably not going to work. (also, I'm sticking with the iPod touch).

Hannity Debate: Should America be Sending Foreign Aid to Egypt? - YouTube
On Fox News on March 4, 2013, Jay Sekulow and Mark Hannah debate whether the US should be providing aid to Egypt in the wake of its revolution, ...

'It was scary': widow speaks out as Muslim cleric pleads guilty to sending offensive letters to families ...
The young widow of fallen Australian soldier Brett Till still recalls the fear that came after she opened a letter sent to their home that labelled ...

Resources last updated: 11/30/2015 8:17:42 AM