Sql Data Reader (varsa olayı) ve SMTP Mail Server İşlemleri

protected void Button1_Click1(object sender, EventArgs e)
   {
       SqlConnection tcnoverginobaglanti = new SqlConnection(cs1);
       SqlCommand tcvergisorgusu = new SqlCommand("select TCNO_VERGINO from WEB_MUSTERI", tcnoverginobaglanti);
       tcnoverginobaglanti.Open();
       SqlDataReader dr = tcvergisorgusu.ExecuteReader();

       int sayac = 0;
       while (dr.Read())
       {
           string tcnovergino = dr["TCNO_VERGINO"].ToString();
           if (tcnovergino == txtTcVergi.Text)
           {
               sayac++;
           }
       }
           
       dr.Close();
       tcnoverginobaglanti.Close();



       
       if(sayac != 0)
       {
           SqlConnection mailbaglanti = new SqlConnection(cs1);
           SqlCommand epostasorgu = new SqlCommand("select eposta from WEB_MUSTERI where TCNO_VERGINO = '" + txtTcVergi.Text + "'", mailbaglanti);
           mailbaglanti.Open();
           string mailadresi = epostasorgu.ExecuteScalar().ToString();
           mailbaglanti.Close();


           SqlCommand sifresorgu = new SqlCommand("select sifre from WEB_MUSTERI where TCNO_VERGINO = '" + txtTcVergi.Text + "'", mailbaglanti);
           mailbaglanti.Open();
           string sifre = sifresorgu.ExecuteScalar().ToString();
           mailbaglanti.Close();



           if (mailadresi != txtKime.Text)
           {
               ScriptManager.RegisterStartupScript(this, GetType(), "Popup", "epostauyari();", true);
           }

           else
           {
               MailMessage ePosta = new MailMessage();
               ePosta.From = new MailAddress("nmert@caglayangrup.com.tr");
               ePosta.To.Add(txtKime.Text);
               //ePosta.Subject = txtKonu.Text;
               ePosta.Subject = "Şifreniz Gönderildi..";
               //ePosta.Body = txtIcerik.Text;
               ePosta.Body = "Şifreniz: " + sifre;
               SmtpClient smtp = new SmtpClient();
               smtp.Credentials = new NetworkCredential("nmert@caglayangrup.com.tr", "nm936879");
               smtp.Port = 587;
               smtp.Host = "smtp.yandex.com.tr";
               smtp.EnableSsl = true;

               smtp.Send(ePosta);
               ScriptManager.RegisterStartupScript(this, GetType(), "Popup", "epostagonderildi();", true);
           }

       }
       else
       {
          ScriptManager.RegisterStartupScript(this, GetType(), "Popup", "bosuyari();", true);
       }
       
  }

Mail server Kurulumu İçin aşağıdaki Linkten Ulaşabilirsiniz..
https://www.youtube.com/watch?v=WLFS2gYIDUI

Hiç yorum yok:

Yorum Gönder