View Full Version : email from a .net form
mlawrence
03-17-2004, 03:37 AM
This may help you.
http://forum.discountasp.net/topic.asp?TOPIC_ID=585
marlatim
03-17-2004, 07:17 AM
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 = "timmarla1@comcast.net";
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.
marlatim
03-17-2004, 07:26 AM
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.
mlawrence
03-17-2004, 08:45 AM
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.
marlatim
03-17-2004, 09:49 AM
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 = "you@hotmail.com";
mailmessage.From = "me@hotmail.com";//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.
Janet
03-23-2004, 03:28 AM
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
Janet
03-23-2004, 03:29 AM
oopps, this was not the forum I clicked on to reply to...sorry
vBulletin® ©Jelsoft Enterprises Ltd.