Thursday, 1 September 2011

Send mail in asp.net

  public static bool sendMail(string from, string subject, string to, string bcc, string body)
    {
        MailAddress mailAddress = new MailAddress(from);
        MailMessage mail = new MailMessage();
        mail.To.Add(to.ToString());
        mail.From = mailAddress;
        mail.Subject = subject;

        mail.Body = body;
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.High;
        SmtpClient smtp = new SmtpClient();
        bool flag = true;
        try
        {

            smtp.Host = smtp.gmail.com; //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential(your gmail id, ur gmail password);
//            smtp.Credentials = new System.Net.NetworkCredential(rrohit_0087@gmail.com,******);
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        }
        catch
        {
            flag = false;
        }
        return flag;
    }

this is the method for sending the mail in this there are 5 parameter pass in this ..
in first enter the pass the gmail id by which you want to send mail
in second pass the subject of the mail
in third pass the id in which you want to send the mail .
in fourth pass the bcc id
in fourth pass the body of mail means what you want to send
---------------------------------------------------------------------------

1 comment:

  1. -----------------------------------------
    smtp.Credentials = new System.Net.NetworkCredential(your gmail id, ur gmail password);
    // smtp.Credentials = new System.Net.NetworkCredential(rrohit_0087@gmail.com,******);
    //Or your Smtp Email ID and Password
    smtp.EnableSsl = true;
    smtp.Send(mail);

    ------------------------------------------
    Gud code Rohit sir...

    ReplyDelete