Sending mail using System.Web.Mail


This is the first time I've sent mail using this method and I'm having a mental block, the code below works fine but for my email body I want to include the text from more than 1 form field. How do I get the page to do this?

<script language=C# runat=server>
void btnSubmit_Click(Object sender, EventArgs e)
string sTo, sFrom, sSubject, sBody;
string sBodyEncoding, sBodyFormat, sMailServer;
int iLoop1;
sTo = "toaddress";
sFrom = "fromaddress";
sSubject = "subject";
sBody = Request.Form["formfield"];
sMailServer = "localhost";
MailMessage MyMail = new MailMessage();
MyMail.From = sFrom;
MyMail.To = sTo;
MyMail.Subject = sSubject;
MyMail.Body = sBody;
SmtpMail.SmtpServer = sMailServer;
lblMsg1.Text="C# Message sent to " + MyMail.To;
2/4/2004 12:14:32 AM 91979 articles. 4 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 22

Just build up a string of everything you want in the body:

sBody = "Field1: " + Request.Form["formfield1"] + "\r\n" +
"Field2: " + Request.Form["formfield2"] + "\r\n" +
"Field3: " + Request.Form["formfield3"] + "\r\n";

C# / C++ Developer
2/4/2004 12:35:53 AM
Also, you may want to check out the StringBuilder class which uses the System.Text namespace.
2/4/2004 2:13:38 AM
Thanks for that - I was trying to use & instead of +
2/4/2004 9:00:08 AM

Similar Artilces:

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

Sending Mail Using System.Net.Mail with out using User credentials
HI, I have an application where in i send mails based on some condition, the user is already authenticated, so i need not check the User Credentials.Right now this is how the piece lokks:- mailClient.Credentials = new NetworkCredential(USERID, USER_PWD,DOMAIN); I want to send the mail, with out validating the user credentials, Can i skip the above line. Please post aqlong with the sample code.   Thanx in Advance. Anil Kumar.   I think you cannot skip. but store user credentials in session variables after login and then pass.If this post was useful to you, please mark it as...

Problem with difference between System.Web.Mail and System.Net.Mail in using attachments
I have a web .Net app which sends emails with attachments.  After the email is sent I clean up aftermyself and delete the attachments from disk.   In upgrading to .Net 2  I changed the email logic from using system.web.mail to  (of course vs is telling me system.web.mail is obsolete).In .Net 1.1,  the files deleted with no problem but in .Net 2 when I attempt to delete  I receive The process cannot access the file ...' because it is being used by another process. If I change the code back to using system.web.mail I can delete the file...

What additional advantage we get through over the old system.web.mail?
What additional advantage we get through over the old system.web.mail?Is it needed to configure the smtp server? Plz tell me the steps to develop the email sending facility in our applicationSwati Jain Take a look at Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue....

Sending Mail Using SYSTEM.WEB.MAIL...
Hello: I have been experiencing a very strange problem that was not there before in the past. When I use the system.web.mail class to send e-mail... most of the messages trying to be sent result in an error while some go through very strange... In my code I specify a valid remote mail server, a valid to and from e-mail addresses on the same domain... Some of the e-mails go through some do not... here is the error below from the e-mails that do not go through... Send failure: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetIn...

get mail using System.Net.Mail
How can i get Email usign System.Net.Mail ?? Hello poloxy  ,the System.Net.Mail used only for sending emails and not to receive them.Read the full documentation at  MSDN Library  Hosam Kamel Remember to click on Mark as answer on the post that helped you SO how can I receive mail ? Try one of these pop3 libraries  Hosam Kamel Remember to click on Mark as answer on the post that helped you HI,   if you want to send email by using System....

Problem in sending mail using
I am using C# and ASP.Net2.0 for sending mail. But my problem is it is not being sent. I am not being able to understand it. I am using my gmail account for it. I am using System.Net and System .Net.Mail for sending the same. But i am getting the error ''Failure Sending Mail. Cannot connect to the server" . I have internet connection. Plz help me. It's urgent. I am attaching my code.  MailMessage mailMsg = new MailMessage();MailAddress ma = new MailAddress(; mailMsg.From = ma; mailMsg.To.Add(s);mailMsg.Subject = "Your...

System.web.mail to
I converted a web app from VS 2003 to VS 2005. i now get error message when i build it  stating system.web.mail  is obsolute,  use i redefine to but now i get other error message such as smtpMail does not exist in the current context. cannot implicitly convert type string to System.Net.Mail.MailAddress   so System.Web.Mail want work in web app convert to VS 2005 running on framework 2.0?           because if i change to System.Net.Mail  i am ...

need help: sending mail using
hi thr.. i am some help urgently.. i need to send mail using the cs code is          System.Net.Mail.MailMessage MyMail = new System.Net.Mail.MailMessage();        SmtpClient SmtpMail = new SmtpClient();            try            {                MyMail.From = new MailAddress("");  &n...

Help for Visual web dev isolate system.web.mail to
Hi all,  I'm new user to visual web developer express software. Laterly i found this application isolate quite some of the component namespace, like system.web.mail to net.mail. I not well understand how functional?? Does it act same as system.web.mail?? My coding below: change system.web.mail to which causing a lot error... *****Can anybody correct me or advise me how to make this code work in <%@import Namespace="" %> <script runat="server">    Public FromAddress As String = "" .......

How to send Mail using System.Net.Mail outside the company network?
Hi All, I am trying to send mail to my ( account, but its not going and throwing error like "Mailbox unavailable. The server response was: <> No such user here". Its working fine if i will send to our company ids. Please help me out. Code: SmtpClient smtp = new SmtpClient();smtp.Host = ""; smtp.Port = 25; //smtp.Credentials = CredentialCache;MailMessage msg = new MailMessage();MailAddress from = new MailAddress(txtFrom.Text); msg.Sender = from; msg.From = from;  string[] tos = txtTo.Text...

What is the maximum size of attachement in sending mail using
I am able to send mail with attachement using System.Net.Mail. But I want to know the maximum size limit of aatchement. Thanks, Prashant It depends on your smtp server settings  MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets Hello Mudassar Khan, Thank you very much for your reply.  Where and how to set this setting in my SMTP server???? And one more thing I want to know that there is any limit of the message body size or message size that can be sent using   Thanks, P...

Migrating from System.web.mail to
Hi Every1,I've recently used the System.web.mail to send mail, using the IIS's smtp server.Doing this, i didn't really need to do anything in the web.config file or give any special parameters to the client. It just assumed i was working with my very own smtp service that came with the IIS and everything worked fine.Now i migrated to and now i need to insert my smtp service's host location under <> in the web.config file.However, i don't know what to write there so the client will use my smtp sevice (host="localhost" doesn't work)can any1 help me on this one?t...

Changing System.Web.Mail to System.Net.Mail
I am trying to learn ASPI have been using the Visual Web Developer 2005I have the following line that I can not work out how to convert.<%Dim FromForm As String = ""Dim ToMe As String = ""Dim FormSubject As String = "Contact Infomation"Dim EmailText As String = "Blar Blar Blar"System.Web.Mail.SmtpMail.Send(FromForm,ToMe,FormSubject,EmailText)%>It tells me that I cannot use System.Web.Mail any more and should use System.Net.Mail. I have been unable to work out what the new code should be to get it to work.The Language is VBCan anyone tell me how to change...

Web resources about - Sending mail using System.Web.Mail -

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 Sending Perez Hilton More Traffic than Google, Driving 3.3% of All US Traffic to Video Sites ...
For media companies evaluating their Facebook marketing strategy , here’s an interesting sign of the times: web analytics firm Hitwise is reporting ...

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 ...

Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the ...
Get Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the App Store. See screenshots and ratings, ...

Cynthia McKinney - responds to Obama on sending troops into Afghanistan - Debate Answer - YouTube
Cynthia McKinney, Green Party Presidential candidate, responds to Barack Obama on his support for sending troops into Afghanistan. Based on his ...

Great-grandmother 'would die' before sending kids to Italy
Great-grandmother 'would die' before sending kids to Italy

Resources last updated: 12/23/2015 9:54:43 PM