C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Send Web Page as Email


Posted Date: 17 Mar 2007    Resource Type: Code Snippets    Category: Email

Posted By: DotNetGuts (DNG)       Member Level: Diamond
Rating:     Points: 10



This code sample shows how to send a web page as email.

Take 4 Textbox control
1 - For URL typing (URL of webpage you want to send as a mail).
2 - For To Field (Email address of user sending the page.)
3 - For From Field (Destination Email address you want to send).
4 - For Subject Line

Now, switch to code view


//Function which convert URL information as string
//Which is used latter to passed as body message.
private String readHtmlPage(string url)
{
String result;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}


//Code for sending webpage as email.
private void btnSend_Click(object sender, System.EventArgs e)
{
//URL is converted into string message.
String message=readHtmlPage(txtURL.Text);
String mailServer = "192.168.0.10"; //Change with your mail server address.


try
{
MailMessage Mailer = new MailMessage();
Mailer.From = txtFrom.Text;
Mailer.To = txtTo.Text;
Mailer.Subject = txtSubject.Text;
Mailer.Body = message;
Mailer.BodyFormat = System.Web.Mail.MailFormat.Html;
SmtpMail.Server(mailServer);
SmtpMail.Send(Mailer);
lblResult.Text = "Page successfully sent!";
}
catch(Exception ex)
{
lblResult.Text = "An error occurred: " + ex.ToString();
}

}





Responses

Author: Kapil Dhawan    17 Jun 2008Member Level: Gold   Points : 2
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys
Thanks to you
Regards,
Kapil



Author: Phani    17 Jun 2008Member Level: Silver   Points : 1
Hi
Informative Post
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys



Author: siva    08 Jul 2008Member Level: Silver   Points : 0
THANKS FOR SHARING UR KNOWLEGE WITH US
REGARDS,
SIVA


Author: Anjali Sharma    11 Jul 2008Member Level: Gold   Points : 1
hi
thnx a lot
at last i got this code
i ve been searching this for many days
but i was not successful
now i may try it out in my application

thnx again



Author: Muralee Krishnan.K    14 Jul 2008Member Level: Gold   Points : 1
Hello
Good piece of code
I hope to see more code from your side
This code will help lots of guys
Thanks to you
Regards,
Muralee


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Send Email programmatically using your Gmail account
Previous Resource: Send eMail in ASP.Net 1.1
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use