Wednesday, September 9, 2009

Send Mail Method

 

public static int SendMail(string subject, string body, string to, string from)

  {

            try

            {

                MailAddress mailto = new MailAddress(to);

                MailAddress mailfrom = new MailAddress(from);

                MailMessage objmail = new MailMessage(from, to, subject, body);

                SmtpClient sclient = new SmtpClient();

                if (ConfigurationManager.AppSettings["smtphost"] != null)

                    sclient.Host = ConfigurationManager.AppSettings["smtphost"].ToString();

                sclient.Send(objmail);

                return (1);

            }

            catch

            {

                return (0);

            }

  }

No comments: