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

Hi,

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.
 

Thanks! 


       
      
    


 

0
Ranginald
2/23/2007 11:42:04 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
1194 Views

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: http://converter.telerik.com/
0
mbanavige
2/24/2007 1:51:42 AM
Perfect!  Thanks so much!
0
Ranginald
2/24/2007 3:53:53 AM
Reply:

Similar Artilces:

System.Net.Mail
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"); oWnd.center();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 - www.findingsteve.net"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 system.net.Mail 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 = "myname@ourmail.com" 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 dotnetslackers.com/Community/blogs/haissam/archive/2007/03/19/Sending-Email-Using-System.Net.Mail.aspx weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx aspnet.4guysfromrolla.com/articles/072606-1.aspx  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("Sheldon@SheldonPenner.com") mail.To.Add("Sheldon.Penner2@verizon.net") 'set the content mail.Subject = "This is an email" mail.Body = "this is the body content...

Sending email using System.net.Mail
 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("myemail@domain.com"); message.To.Add(new MailAddress("someone@domain.com")); message.Subject = "Test"; message.Body = "This is a test message"; message.IsBodyHtml = false; SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587); mailClient.Credentials = ne...

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

System.Net.Mail
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 127.0.0.1 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 asp.net 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("me@mycompany.com") mail.To.Add("smpenner@juno.com") '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(noReply@westernair.com);MailAddress objToMailAddress = new MailAddress(benc@westernair.com);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(smtp.horasoft.in)plz 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("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "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 system.net.mail
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...

system.net.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 system.net.mail -- problem with strings and body of the email. - asp.net.getting-started

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