Esempio n. 1
0
        public IActionResult ContactUs(MailVM modelView)
        {
            var amount    = modelView.CatchpaNumber[0] + modelView.CatchpaNumber[1];
            var testValid = !ModelState.IsValid;

            if (amount != modelView.Catchpa)
            {
                testValid = false;
            }
            else
            {
                testValid = true;
            }
            if (!testValid)
            {
                TempData[modelView.TempDataFail] = "Räkna om... Hallå eller...";
                return(View(modelView));
            }
            else
            {
                dataManager.SendEmail(modelView);
                TempData[modelView.TempDataSuccess] = "Ditt mail har skickats!";
            }

            return(RedirectToAction(nameof(ContactUs)));
        }
Esempio n. 2
0
        public PartialViewResult _MailList(string query, string list)
        {
            if (query == null)
            {
                query = "";
            }
            if (list == null)
            {
                list = "";
            }
            MailVM VM = new MailVM
            {
                InboxList = db.Mails.Where(x => x.IsActive).OrderByDescending(x => x.IsNew).ToList(),
                TrashList = db.Mails.Where(x => x.IsActive != true).OrderByDescending(x => x.IsNew).ToList()
            };

            if (list == "Inbox")
            {
                VM.InboxList = db.Mails.Where(x => x.IsActive && x.Name.Contains(query)).OrderByDescending(x => x.IsNew).ToList();
            }
            else if (list == "Trash")
            {
                VM.TrashList = db.Mails.Where(x => x.IsActive != true && x.Name.Contains(query)).OrderByDescending(x => x.IsNew).ToList();
            }

            return(PartialView(VM));
        }
Esempio n. 3
0
        internal MailVM RandomTwoNumbers(MailVM mailVM)
        {
            mailVM.CatchpaNumber[0] = RandomCatchpa()[0];
            mailVM.CatchpaNumber[1] = RandomCatchpa()[1];

            return(mailVM);
        }
Esempio n. 4
0
        public ActionResult SendEmail(MailVM model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var senderEmail   = new MailAddress("*****@*****.**");
                    var receiverEmail = new MailAddress("*****@*****.**", "Receiver");
                    var body          = model.Message;

                    var smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = true,
                        Credentials           = new NetworkCredential(senderEmail.Address, "cagatay123")
                    };
                    using (var mess = new MailMessage(senderEmail, receiverEmail)
                    {
                        Body = body
                    })
                    {
                        smtp.Send(mess);
                    }
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Some Error";
            }
            return(View());
        }
Esempio n. 5
0
        public IActionResult ContactUs()
        {
            MailVM mailVM = new MailVM();

            mailVM.CatchpaNumber[0] = dataManager.RandomCatchpa()[0];
            mailVM.CatchpaNumber[1] = dataManager.RandomCatchpa()[1];

            return(View(mailVM));
        }
Esempio n. 6
0
        public PartialViewResult _MailNav()
        {
            MailVM VM = new MailVM
            {
                InboxCount = db.Mails.Where(x => x.IsActive).ToList().Count,
                TrashCount = db.Mails.Where(x => x.IsActive != true).ToList().Count
            };

            return(PartialView(VM));
        }
Esempio n. 7
0
        public ActionResult MailDetay(DateTime date)
        {
            MailVM m = new MailVM();

            using (ImapClient client = new ImapClient("imap.yandex.com.tr", 993, "*****@*****.**", "Umurbey.17", AuthMethod.Login, true))
            {
                IEnumerable <uint>        uids1    = client.Search(SearchCondition.All());
                IEnumerable <MailMessage> messages = client.GetMessages(uids1);
                MailMessage item = messages.FirstOrDefault(x => x.Date() == date);

                m.from       = item.From.DisplayName;
                m.Subject    = item.Subject;
                m.Date       = item.Date().Value;
                m.Body       = item.Body;
                m.Attachment = item.Attachments;
            }
            return(View(m));
        }
Esempio n. 8
0
        public ActionResult Email(string folder)
        {
            List <MailVM> mails = new List <MailVM>();

            using (ImapClient client = new ImapClient("imap.yandex.com.tr", 993, "*****@*****.**", "Umurbey.17", AuthMethod.Login, true))
            {
                IEnumerable <uint>        uids1    = client.Search(SearchCondition.All(), mailbox: folder);
                IEnumerable <MailMessage> messages = client.GetMessages(uids1);
                foreach (var item in messages)
                {
                    MailVM m = new MailVM();
                    m.from       = item.From.DisplayName;
                    m.Subject    = item.Subject;
                    m.Date       = item.Date().Value;
                    m.Read       = true;
                    m.Attachment = item.Attachments;
                    m.Body       = item.Body;
                    mails.Add(m);
                }
            }

            return(View(mails.OrderByDescending(x => x.Date).ToList()));
        }
Esempio n. 9
0
        public void SendEmail(MailVM mailVM)
        {
            string toAddress   = configuration["epost"];
            string fromAddress = configuration["epost"];
            string subject     = mailVM.Subject;
            //string message = mailVM.Message + "\nAnkommande epost: "+ mailVM.Email;
            var message = new StringBuilder();

            message.Append($"Name: {mailVM.Name}\n");
            message.Append($"Email: {mailVM.Email}\n");
            message.Append($"Message:  {mailVM.Message} \n\n");
            message.Append(mailVM.Message);

            var mail       = new MailMessage();
            var smtpClient = new SmtpClient(configuration["smtpserver"], int.Parse(configuration["port"]));

            try
            {
                using (mail)
                {
                    string email    = configuration["epost"];
                    string password = configuration["password"];

                    var loginInfo = new NetworkCredential(email, password);

                    mail.From = new MailAddress(fromAddress);
                    mail.To.Add(new MailAddress(toAddress));
                    mail.Subject    = subject;
                    mail.Body       = message.ToString();
                    mail.IsBodyHtml = true;

                    try
                    {
                        using (smtpClient)
                        {
                            smtpClient.EnableSsl             = true;
                            smtpClient.UseDefaultCredentials = false;
                            smtpClient.Credentials           = loginInfo;
                            smtpClient.Send(mail);
                        }
                    }
                    finally
                    {
                        mail.Dispose();
                    }
                }
            }
            catch (SmtpFailedRecipientsException ex)
            {
                foreach (SmtpFailedRecipientException t in ex.InnerExceptions)
                {
                    var status = t.StatusCode;
                    if (status == SmtpStatusCode.MailboxBusy ||
                        status == SmtpStatusCode.MailboxUnavailable)
                    {
                        Thread.Sleep(5000);
                        smtpClient.Send(mail);
                    }
                }
            }
        }
Esempio n. 10
0
        public ActionResult ForgotPassword(MailVM mailView)
        {
            string[] mailTo;
            MailDTO  mail;
            bool     isMailSent      = false;;
            bool     isResetPassword = false;
            int      UserMasterId;

            string newPassword          = null;
            string newPasswordEncrypted = null;

            if (mailView != null)
            {
                UserMasterId = _mail.CheckMail(mailView.To);
                if (UserMasterId != 0)
                {
                    PasswordGenerator.PasswordGenerator passGen = new PasswordGenerator.PasswordGenerator();
                    passGen.InitializePasswordArrays();

                    PasswordVM passVM = new PasswordVM();
                    passVM.CapitalLettersLength    = 1;
                    passVM.DigitsLength            = 1;
                    passVM.SmallLettersLength      = 3;
                    passVM.SpecialCharactersLength = 1;
                    passVM.PasswordLength          = 6;

                    newPassword = passGen.GeneratePassword(passVM); // get password

                    if (!string.IsNullOrEmpty(newPassword))
                    {
                        newPasswordEncrypted = encrypt.encryption(newPassword);//Encrypt Password

                        isResetPassword = _resetPassSvc.ResetPassword(newPasswordEncrypted, UserMasterId);
                        if (isResetPassword)
                        {
                            mail                       = new MailDTO();
                            mail.From                  = "*****@*****.**";
                            mail.IsBodyHtml            = false;
                            mail.MailSubject           = "Reset Password";
                            mail.MailBody              = "Your new password which is reset is: " + newPassword;
                            mail.SmtpPort              = 587;
                            mail.SmtpServer            = "smtp.gmail.com";
                            mail.EnableSSL             = true;
                            mail.UseDefaultCredentials = true;
                            //split the ';' separated string To a List
                            mailTo      = mailView.To.Split(';');
                            mail.ToList = new List <string>();
                            for (int i = 0; i < mailTo.Length; i++)
                            {
                                mail.ToList.Add(mailTo[i]);
                            }
                            //instantiate CC and Bcc List if possible
                            isMailSent = _mail.SendMail(mail);// call SendMail method to send the mail
                            if (isMailSent)
                            {
                                mailView.SuccessOrFailureMessage = "Your new password: "******" is sent to mail";
                                mailView.MessageColor            = "green";
                            }
                            else
                            {
                                mailView.SuccessOrFailureMessage = "Your password was not reset in a proper manner";
                                mailView.MessageColor            = "red";
                            }
                        }
                    }
                }
                else
                {
                    mailView.SuccessOrFailureMessage = "Sorry your email was incorect. Please enter again";
                    mailView.MessageColor            = "red";
                }
            }
            return(View(mailView));
        }
Esempio n. 11
0
        public ActionResult ForgotPassword()
        {
            MailVM mailVM = new MailVM();

            return(View(mailVM));
        }