public bool SendEMail(SmtpMailEntity mailEntity)
        {
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.IsBodyHtml = false;
                mail.From       = new MailAddress(mailEntity.senderEMailAdress);
                mail.To.Add(mailEntity.receiverEMailAdress);
                mail.Subject = mailEntity.subject;
                mail.Body    = mailEntity.body;

                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential(mailEntity.senderMailUsername, mailEntity.senderMailPassword);
                SmtpServer.EnableSsl   = true;

                SmtpServer.Send(mail);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        public ActionResult Create([Bind(Include = "ID,Username,Password,AccountTypeID")] Accounts accounts)
        {
            var username = (from user in db.Accounts
                            where user.Username == accounts.Username
                            select user).Any();

            if (!username) // Daha önce kullanılmış mı kontrolü
            {
                if (ModelState.IsValid)
                {
                    SmtpMailEntity mailEntity = new SmtpMailEntity
                    {
                        senderEMailAdress   = "*****@*****.**",
                        receiverEMailAdress = accounts.Username,
                        senderMailUsername  = "******",
                        senderMailPassword  = "******",
                        subject             = "Registered E Commerce",
                        body = "Thanks for be registered E Commerce Family"
                               + Environment.NewLine
                               + "Your username: "******"Your password: "******"Love,"
                               + Environment.NewLine +
                               "E Commerce Family"
                    };

                    SmtpMailApi smtpMailApi = SmtpMailApi.Instance;
                    smtpMailApi.SendEMail(mailEntity);


                    accounts.AccountTypeID = 2;

                    Encryption enc = new Encryption();
                    accounts.Password = enc.Encrypt(accounts.Password); // Şifreleme işlemi yapılarak veri tabanına ekliyoruz.

                    db.Accounts.Add(accounts);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Login"));
                }
            }
            else
            {
                Response.Write("<script>alert('Başka bir kullanıcı adı giriniz.')</script>"); // Hata Mesajı
            }


            ViewBag.AccountTypeID = new SelectList(db.AccountTypes, "ID", "Name", accounts.AccountTypeID);
            ViewBag.ID            = new SelectList(db.Companies, "ID", "Name", accounts.ID);
            return(View(accounts));
        }