示例#1
0
        public Boolean SendMail(string from, List<string> emailList, string subject, string bodyHtml, TForm newForm, Int32 formId, SystemUsers sentUser)
        {
            try
            {
                MailMessage completeMessage = new MailMessage();
                completeMessage.From = new MailAddress(from);
                completeMessage.Subject = subject;
                completeMessage.Body = bodyHtml;
                completeMessage.IsBodyHtml = true;

                //SmtpClient client = new SmtpClient("TingleNT30.wctingle.com");
                //client.UseDefaultCredentials = true;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.Credentials = new NetworkCredential("*****@*****.**", "ZXCasdQWE123!");
                client.EnableSsl = true;

                using (FormContext ctx = new FormContext())
                {

                    foreach (string email in emailList)
                    {

                        RequestNotifications newRN = new RequestNotifications
                        {
                            Form = ctx.TForms.FirstOrDefault(x => x.FormID == newForm.FormID),
                            BodyHtml = bodyHtml,
                            RequestedFormId = formId,
                            SentBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == sentUser.SystemUserID),
                            Status = 0,
                            Timestamp = DateTime.Now,
                            ToEmailAddress = email
                        };

                        ctx.RequestNotifications.Add(newRN);
                        ctx.SaveChanges();

                        try
                        {
                            completeMessage.To.Clear();
                            completeMessage.To.Add(email);
                            client.Send(completeMessage);

                            newRN.Status = 1;

                            ctx.SaveChanges();
                        }
                        catch(Exception exc)
                        {}

                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
                //throw ex;
            }
        }
        public Int32 GetListID(TForm tForm)
        {
            if (!String.IsNullOrEmpty(tForm.FormID.ToString()))
            {
            }

            return 0;
        }