using System.Net.Mail;
using System.Net;
using System.IO;
using System.Text;
///
protected void SendEmail(DataSet ds)
{
MailMessage regMsg = new MailMessage();
regMsg.From = new MailAddress(ConfigurationManager.AppSettings["SendFrom"].ToString(), ConfigurationManager.AppSettings["sender"].ToString(), System.Text.Encoding.UTF8);
regMsg.To.Add(txtEmil.Text);
regMsg.Subject = "Successful registration";
regMsg.ReplyTo = new MailAddress(ConfigurationManager.AppSettings["ReplyTo"].ToString(), ConfigurationManager.AppSettings["sender"].ToString());
//regMsg.Body = "<h2>This is an HTML-Formatted Email Send Using the <code>IsBodyHtml</code>=Property</h2><p>Isn't HTML <em>neat</em>?</p><p>You can make all sorts=of <span style=3D'color:red;font-weight:bold;'>pretty colors!!</span>.</p>";
//regMsg.Body = "<iframe src='http://www.baidu.com'></iframe>";
regMsg.IsBodyHtml = true;
regMsg.BodyEncoding = Encoding.UTF8;
// method 1
WebRequest therequest = WebRequest.Create(ConfigurationManager.AppSettings["sendUri"].ToString());
WebResponse theresponse = therequest.GetResponse();
Stream thestream = theresponse.GetResponseStream();
StreamReader sr = new StreamReader(thestream, System.Text.Encoding.Default);
regMsg.Body = sr.ReadToEnd();
sr.Close();
thestream.Close();
//method 2
//WebClient wc = new WebClient();
//wc.Credentials = CredentialCache.DefaultCredentials;
//Byte[] pageData = wc.DownloadData(ConfigurationManager.AppSettings["sendUri"].ToString());
//regMsg.Body = Encoding.Default.GetString(pageData);
//wc.Dispose();
//SmtpClient client = new SmtpClient("localhost");
//client.UseDefaultCredentials = true;
//method 3
//MailMessage message = new MailMessage(ConfigurationManager.AppSettings["SendFrom"].ToString(), txtEmil.Text);
//message.Subject = "Successful registration";
//message.IsBodyHtml = true;
//message.BodyEncoding = Encoding.UTF8;
//SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"].ToString());
//WebRequest therequest = WebRequest.Create(ConfigurationManager.AppSettings["sendUri"].ToString());
//WebResponse theresponse = therequest.GetResponse();
//Stream thestream = theresponse.GetResponseStream();
//StreamReader sr = new StreamReader(thestream, System.Text.Encoding.Default);
//message.Body = sr.ReadToEnd();
//sr.Close();
//thestream.Close();
//client.Send(message);
SmtpClient client = new SmtpClient();
//client.Host = "localhost";
client.Credentials = CredentialCache.DefaultNetworkCredentials;
//object userState = regMsg;
try
{
//client.SendAsync(regMsg, userState);
client.Send(regMsg);
}
catch
{
}
}