devnewbee
asked on
How can I send form results in an email using asp.net?
I produce a results page for my users after they complete a .net wizard. What is the best way to have the results page emailed to them?
You could use System.Net.Mail
Here's a good website:
http://www.systemnetmail.com/
and I've attached a quick snippet of code I tend to use more often.
Hope that Helps!
Steve
Here's a good website:
http://www.systemnetmail.com/
and I've attached a quick snippet of code I tend to use more often.
Hope that Helps!
Steve
MailMessage mail = new MailMessage();
//From E-mail Address
mail.From = new MailAddress("from@yourdomain.com");
//To E-mail Address
mail.To.Add(new MailAddress("to@userdomain.com"));
//Subject of E-mail
mail.Subject = "Subject Line";
//E-mail Message
mail.Body = "Message Body";
//Now the fun part...
try
{
//if you are using an Internal Mail Server
//you can use this:
SmtpClient smtp = new SmtpClient("internal.mailserver.com");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//Or if you're using an external mail server
//You can use this:
SmtpClient smtp = new SmtpClient();
smtp.Host = "external.mailserver.com";
smtp.Port = 587;
//If you are not using default Credentials:
System.Net.NetworkCredential SmtpUserInfo = new System.Net.NetworkCredential("username", "password");
smtp.UseDefaultCredentials = false;
smtp.Credentials = SmtpUserInfo;
//SSL
smtp.EnableSsl = true;
//The most important line of all... Sending the e-mail!
smtp.Send(mail);
}
catch (Exception ex)
{
}
ASKER
Awesome guys. The only question i have is how do I save the .aspx page as text in the body tag of your code and use an address the user enters? Do I call a textbox in the "TO" section?
ASKER
I would like ...objEmail.BODY="body of message" to equal the rendered .aspx page to be save in text.
ASKER
I figured out the TO problem. No all I have left is to assign the rendered results to the body of the message. How is this best done?
Where are the rendered results coming from?
Is this something you have coded?
Is this something you have coded?
ASKER
They are just some static and dynamically generated tables that show on the page. is there a way of just sending what is visible in an email to the user?
ASKER
if I save in a text format it works. How can I do this prior to sending the email and call for txt file to send as an attachement or just send embedded?
You will have to intercept the rendering stream and save it to a text file.
Attached a snippet you can play with
Attached a snippet you can play with
private void Page_Load(object sender, System.EventArgs e)
{
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);
Page.RenderControl(oHtmlTextWriter);
oHtmlTextWriter.Flush();
System.IO.FileStream fs = new
System.IO.FileStream(@"C:\temp\test.htm",System.IO .FileMode.Create);
string s= oStringWriter.ToString();
byte[] b = System.Text.Encoding.UTF8.GetBytes(s);
fs.Write(b,0,b.Length);
fs.Close();
Response.End();
}
ASKER
This is great. The only concern I have is that is the final step of my wizard that the results happen on. iIsee the above code is initiated on page_load. is there another placa I should call the above code instead?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is button Code below
Open in new window