I want to send emails in HTML format. How can I use asp.net to generate HTML content for emails.
- Using output of .aspx page(Tried there was nothing in email body. Must be something in page that can’t be used for email)
- Using Webcontrol and get web control output and use it as email body.
- Using custom http handler so can call handler to get email body.
Can you please suggest what would be the best solution?
Some guide or sample reference would be great if know one.
Thanks for all answers:
I am implementing code below:
string lcUrl = 'http://localhost:50771/webform1.aspx'; // *** Establish the request HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(lcUrl); // *** Set properties //loHttp.Timeout = 10000; // 10 secs loHttp.UserAgent = 'Code Web Client'; // *** Retrieve request info headers HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse(); Encoding enc; try { enc = Encoding.GetEncoding(loWebResponse.ContentEncoding); } catch { enc = Encoding.GetEncoding(1252); } StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc); string lcHtml = loResponseStream.ReadToEnd(); loWebResponse.Close(); loResponseStream.Close();
I did this, essentially we had a page that the user could view, and then they could click a button and send the html on the page in an email. Basically my page was responsible for generating the email. I did this by overriding the Render method, and providing my own stream or using the one passed to us. We did this dpeneding on if we were rendering what the user would see or emailing it.
One thing to note is you have to make sure all links are fully qualified. You might be able to use the base functionality. this is what I was doing in the RemapImageUrl basically I appended an absolute path on all my image files.