• Home
  • Trace mobile number (From India)
  • Entertainment
  • SiteMap
  • Home
  • ASP.NET
  • C#
  • BLOGGING
  • SQL SERVER
  • FACEBOOK
  • Entertainment

System.Web.Mail does not support sending a web page through Email but we can use WebRequest class to get screen scrape web pages, and we can pass the resulting Html string to the MailMessage class.
Here is step by step Guidline how will you achieve that goal.



Add the following namespace
using System.Net;
using System.IO;
using System.Net.Mail;

private string getPageHtml(string url)
{
WebRequest objCreateReq = System.Net.HttpWebRequest.Create(url);
StreamReader ObjSreader = new StreamReader(objCreateReq.GetResponse().GetResponseStream());
string PageHtml = ObjSreader.ReadToEnd();
ObjSreader.Close();
return PageHtml;
}

protected void sendMail()
{
MailMessage Mymail = new MailMessage();
Mymail.To.Add("toEmailhere");
Mymail.From = new System.Net.Mail.MailAddress("yourEmailhere");
Mymail.Subject = "this is a test email to send a web page in email.";
string url = "http://www.microsoft.com/en-us/default.aspx";
Mymail.Body = getPageHtml(url);
Mymail.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
//Add the your gmail id and password
client.Credentials = new System.Net.NetworkCredential("gmailEmailID", "GmailPassword");
client.Port = 587; // this is the port where gmail work
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Send(Mymail);

}

Call the send email function to send email
protected void Page_Load(object sender, EventArgs e)
{
sendMail();
}


if you have any problem then please feel free to write comment thanx.
Sending Email is a basic task of a web application for many purposes . If you have any web space somewhere on a web server then you are provided with the Email accounts and SMTP and POP services for sending and receiving E-mails.
If you want to send email using your Gmail account or using Gmail's smtp server in ASP.NET application or if you don't have a working smtp server to send mails using your ASP.NET application or aspx page then sending e-mail using Gmail is best option.
But Gmail allow to send mail to limited number of people per day and you can’t send same email to unlimited number of people Gmail suppose it as spam message.
So if you want to send mail to limited number of people from asp.net page then sending mail through gmail will be best option.
Here I am showing the step by step process .

1-add a new web application in visual studio and add a Web form to it.And add a button on this page.We will use this buttong click event to send Email.

2-Add NameSpace System.Net.Mail by using this
using System.Net.Mail;

3-on the button click event add this code

string Emailfrom = from@gmail.com; //Replace this with your own Gmail id

string Emailto = to@gmail.com //Replace this with the Email Address where you want to send the Email

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(Emailto);
mail.From = new MailAddress(Emailfrom, "hello" , System.Text.Encoding.UTF8);
mail.Subject = "Put your Email subject Here" ;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "put your message here thet you want to sent";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true ;
mail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient();
//Add the your gmail id and password
client.Credentials = new System.Net.NetworkCredential(Emailfrom, "Password");
client.Port = 587; // this is the port where gmail work
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage );
}

Replae to and from email with the real email otherwise code will not work.
Newer Posts Older Posts Home

Most Read

  • How to Capitalize the First Letter of All Words in a string in C# ?
  • keyboard shortcuts For Windows
  • List Of Best Free WordPress Plugins : 2012
  • Read Write XML Data-Read Write XML File Using C#, VB.NET In Asp.Net
  • How to Shake Internet Explorer - Javascript Code
  • How to Choose a Nice Topic for your Blog .
  • Free Search Engine Submission List ,search engine optimization
  • Number validation in Textbox of ASP.NET Using Regular Expression validator
  • Javascript:Percentage Gain Javascript Calculator
  • .Net Interview Questions and Answers on OOPS | OOPS Frequently Asked Questions
Google
Custom Search Bloggers - Meet Millions of Bloggers

Join Us On FaceBook

  • Recent Posts
  • Comments

All Topics

  • ►  2014 (10)
    • ►  January (10)
  • ►  2013 (14)
    • ►  October (1)
    • ►  April (2)
    • ►  March (11)
  • ►  2012 (142)
    • ►  December (25)
    • ►  October (1)
    • ►  September (9)
    • ►  August (2)
    • ►  July (7)
    • ►  June (2)
    • ►  April (5)
    • ►  March (27)
    • ►  February (27)
    • ►  January (37)
  • ▼  2011 (23)
    • ►  December (3)
    • ►  November (6)
    • ►  October (12)
    • ▼  September (2)
      • How to send a web page in Email ?
      • How to send E-mail using ASP.net through Gmail acc...
  • ►  2009 (1)
    • ►  June (1)

Tips & Tricks

  • What is good One Blog and Many Categories, or Many Blogs with One Categories?
  • Adding Twitter tweet button to each Blogger posts.
  • How to Choose a Nice Topic for your Blog .
  • Embedding YouTube Videos ,movie in your blog
  • Facebook iFrame Apps – Getting Rid of Scrollbars
  • Facebook Analytics:How to Set Up Your Website or Blog with Facebook Insights for Domains
  • How To Add Perfect Share Box to Blogger
  • Blogger Free Images Hosting Tip,Free unlimited bandwidth image hosting for Blogger blogs
  • Add “Link to this post” codes below Each blogger posts
  • Free Search Engine Submission List ,search engine optimization
  • Adsense Tips for Maximum CTR
  • List Of Best Free WordPress Plugins : 2012
2012 tectopix. All rights reserved.
Designed by tectopix