Exemplo n.º 1
0
        private void btngonder_Click(object sender, EventArgs e)
        {
            if (txtkullanici.Text == "" || txtmail.Text == "")
            {
                MessageBox.Show("Gerekli alanları doldurunuz!", "Mesaj", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                dbEnginee nesne = new dbEnginee();
                if (nesne.emailkontrol(txtmail.Text) == true)
                {
                    DataTable dtemail = nesne.SifreBul(txtkullanici.Text, txtmail.Text);
                    if (dtemail.Rows.Count == 0)
                    {
                        MessageBox.Show("Sistemdeki kullanıcı adınız ve epostanız eşleşmiyor!", "Mesaj", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        sifreunuttum.Sifre = dtemail.Rows[0]["Sifre"].ToString();
                        ////şifre gönderme
                        try
                        {
                            int    _port               = 587;
                            string _host               = "smtp.live.com";
                            string _clientUserName     = "******";
                            string _fromMail           = "*****@*****.**";
                            string _clientUserPassword = "******";
                            bool   _enableSsl          = true;

                            MailMessage mailMessage = new MailMessage();

                            mailMessage.To.Add(txtmail.Text);
                            mailMessage.IsBodyHtml = true;
                            mailMessage.Body       = @"Şifreniz:" + Sifre;
                            mailMessage.Subject    = @"Şifre Hatırlatma";
                            mailMessage.From       = new MailAddress(_fromMail);

                            SmtpClient smtp = new SmtpClient(_host, _port);
                            smtp.Credentials    = new System.Net.NetworkCredential(_clientUserName, _clientUserPassword);
                            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                            smtp.EnableSsl      = _enableSsl;
                            smtp.Send(mailMessage);
                            MessageBox.Show("Mail başarıyla gönderildi.", "MAIL", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        catch (Exception hata)
                        {
                            MessageBox.Show(hata.Message);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Lütfen geçerli bir mail adresi giriniz", "Geçersiz Mail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }