Beispiel #1
0
        static public bool addMail(string firstName,
                                   string lastName,
                                   string birthday,
                                   string gender,
                                   string phoneNumber,
                                   string school,
                                   string endYear,
                                   string grade,
                                   string password,
                                   string subject,
                                   string message)
        {
            using (IsBasvurusuEntities4 ent = new IsBasvurusuEntities4())
            {
                FormTab f = new FormTab();
                f.firstName   = firstName;
                f.lastName    = lastName;
                f.birthDay    = birthday;
                f.gender      = gender;
                f.phoneNumber = phoneNumber;
                f.school      = school;
                f.endYear     = endYear;
                f.grade       = grade;
                f.password    = password;
                f.subject     = subject;
                f.message     = message;

                ent.Set <Models.FormTab>().Add(f);
                ent.SaveChanges();

                return(true);
            }
        }
        public ActionResult Form(IsBasvurusu.Models.FormTab objModelMail)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string from = objModelMail.adminMail;

                    using (MailMessage mail = new MailMessage(from, objModelMail.adminMail))
                    {
                        mail.Subject = objModelMail.subject;
                        mail.Body    = "First Name: " + objModelMail.firstName + "\n"
                                       + "Last Name: " + objModelMail.lastName + "\n"
                                       + "Gender: " + objModelMail.gender + "\n"
                                       + "Phone Number: " + objModelMail.phoneNumber + "\n"
                                       + "School: " + objModelMail.school + "\n"
                                       + "Degree: " + objModelMail.degree + "\n"
                                       + "Message: " + objModelMail.message + "\n";
                        mail.IsBodyHtml = false;
                        if (objModelMail.attachment.ContentLength > 0)
                        {
                            string fileName = Path.GetFileName(objModelMail.attachment.FileName);
                            mail.Attachments.Add(new Attachment(objModelMail.attachment.InputStream, fileName));
                        }
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host      = "smtp.gmail.com";
                        smtp.EnableSsl = true;
                        NetworkCredential networkCredential = new NetworkCredential(from, objModelMail.password);
                        smtp.UseDefaultCredentials = true;
                        smtp.Credentials           = networkCredential;
                        smtp.Port = 587;
                        smtp.Send(mail);


                        return(ViewBag("send"));
                    }

                    //database kayıt işlemi
                    IsBasvurusu.Models.FormTab.addMail(objModelMail.firstName,
                                                       objModelMail.lastName,
                                                       objModelMail.birthDay,
                                                       objModelMail.gender,
                                                       objModelMail.phoneNumber,
                                                       objModelMail.school,
                                                       objModelMail.degree,
                                                       objModelMail.adminMail,
                                                       objModelMail.password,
                                                       objModelMail.subject,
                                                       objModelMail.message);

                    return(RedirectToAction("Sent"));
                }
                else
                {
                    return(View("FormPage"));
                }
            }
            catch (Exception ex)
            {
                Response.Write("FormPage" + ex.Message);
            }
            return(View("FormPage"));
        }
 public ActionResult FormPage(IsBasvurusu.Models.FormTab form)
 {
     return(View());
 }