示例#1
0
        public static bool send(SentEmailViewModel email)
        {
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("*****@*****.**");

            if (email.CC != null)
            {
                string[] multipleCc = email.CC.Split(';');
                foreach (var cc in multipleCc)
                {
                    mail.CC.Add(new MailAddress(cc));
                }
            }
            string[] multipleTo = email.To.Split(';');
            foreach (var to in multipleTo)
            {
                mail.To.Add(new MailAddress(to));
            }

            mail.Subject = email.Subject;
            mail.Body    = email.Body;
            SmtpClient smtp = new SmtpClient();

            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;

            smtp.Credentials = new NetworkCredential(
                "*****@*****.**", "August@2019");
            smtp.EnableSsl = true;
            try
            {
                smtp.Send(mail);
            }
            catch (Exception ex)

            {
                return(false);
            }
            return(true);
        }
示例#2
0
        public ActionResult Send(SentEmailViewModel model)
        {
            List <SentEmailViewModel> lst = new List <SentEmailViewModel>();

            string[] multipleTo = model.To.Split(';');
            foreach (var to in multipleTo)
            {
                lst.Add(new SentEmailViewModel()
                {
                    To = to
                });
            }
            lst.ForEach(m => m.EmailId = model.EmailId);
            lst.ForEach(m => m.Body    = model.Body);
            lst.ForEach(m => m.Subject = model.Subject);
            lst.ForEach(m => m.CC      = model.CC);
            //lst.lstSentEmails.ForEach(m => m.UserID = model.UserID);
            lst.ForEach(m => m.Date = DateTime.Now);
            if (Email.send(model))
            {
                _iEmailService.AddSentEmails(lst);
            }
            return(RedirectToAction("Index", "Email"));
        }
示例#3
0
        public ActionResult Send()
        {
            SentEmailViewModel model = new SentEmailViewModel();

            return(View(model));
        }