Tuesday, November 18, 2008

Mail Sending Using Net.Mail

0 comments 11/18/2008
Sign up to receive our site updates!

Simple Code For sending Mail Using Net.Mail NameSpace



using System.Net.Mail;

using System.IO;



public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{



}



protected void btnsend_Click(object sender, EventArgs e)

{

MailMessage mm = new MailMessage();

mm.From = new MailAddress("rajesh.chekuri@gmail.com");

mm.To.Add(new MailAddress("rajesh.chekuri@gmail.com"));

mm.Subject ="hii";

mm.Priority = MailPriority.High;

mm.Body = "Thanks for Visiting www.funnydotnet.co.cc";

SmtpClient sc = new SmtpClient("localhost");

try

{

sc.Send(mm);

lblnotice.Text = "Mail sended sucessfully";

}

catch (Exception exc)

{

lblnotice.Text = "Send failure: " + exc.ToString();

}

}

}



//// some times it gives error like

//System.Net.Mail.SmtpFailedRecipientException {"Mailbox unavailable. The

////server response was: 5.7.1 ... Relaying denied. IP name

////possibly forged [208.179.189.145]"}

////System.Net.Mail.SmtpFailedRecipientException



//solution

//You have to allow relaying in your SMTP server.



//Check security settings in IIS.



//This is dine by right-clicking Default SMTP Virtual Server and choosing

//properties.



//Then go to the Access tab. Click on the Relay button at the bottom of the

//dialog.



//Add the IPs you want to grant access. By default this is turned of

//completely and since your web server is on the same machine, you could add

//127.0.0.1 as the only entry in the list.



//You can also open it up completely by checking the radio button All except

//the list below and leave the list blank. However, if it is a public server

//that is not a recommended setting.



//That should solve that issue.

//some times unchecked need to add this code into web.config



//

//

//

//

//

//

//

Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri