Ejemplo n.º 1
0
        public JsonResult Delete(int id = 0)
        {
            try
            {
                BaseEmail model = db.BaseEmails.Find(id);
                if (model != null)
                {
                    BoolString validation = model.BeforeDelete(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet));
                    }
                    db.BaseEmails.Remove(model);
                    db.SaveChanges();
                    validation = model.AfterDelete(db);

                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }, JsonRequestBehavior.AllowGet));
                    }
                    return(Json(new { id = model.id, MessageSucess = "That Email deleted successfully." }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { Message = "This record no longer exists" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Email") }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        private void SendToEmail(string subject)
        {
            var emailFrom = string.IsNullOrEmpty(MyReg.Read("EmailFrom")) ? string.Empty : MyReg.Read("EmailFrom");

            using (SimpleLogin frm = new SimpleLogin(Application.ProductName, emailFrom))
            {
                var result = frm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    BaseEmail email = new BaseEmail(frm.Login, "smtp.gmail.com", "587", frm.Pwd);

                    try
                    {
                        List <string> values = new List <string>();

                        foreach (object o in lbLog.Items)
                        {
                            values.Add(o.ToString());
                        }

                        string selectedItems = String.Join("\n", values);

                        email.SendMessage(subject, selectedItems, "*****@*****.**");

                        MyReg.Write("EmailFrom", frm.Login);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Sending email error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Task InsertMessageAsync(BaseEmail obj, TimeSpan delay, CancellationToken token)
        {
            var queue = _queueClient.GetQueueReference(QueueName.EmailQueue.Name);
            var json  = JsonConvert.SerializeObject(obj, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });
            var cloudMessage = new CloudQueueMessage(json);

            return(queue.AddMessageAsync(cloudMessage, null, delay, new QueueRequestOptions(),
                                         new OperationContext(), token));
        }
Ejemplo n.º 4
0
        public JsonResult get(int id)
        {
            BaseEmail model = db.BaseEmails.Find(id);

            if (model != null)
            {
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Message = "This record no longer exists" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
 public ActionResult Form(int id = 0, string from = "")
 {
     ViewBag.relations = db.VWISRElations.Where(d => d.PK_Table == "BaseEmail").ToList();
     ViewBag.from      = from;
     if (id == 0)
     {
         return(PartialView(new BaseEmail()));
     }
     else
     {
         BaseEmail model = db.BaseEmails.Find(id);
         return(PartialView(model));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Send e-mail using predefined configurations at initialization
        /// </summary>
        public static string Send(BaseEmail email)
        {
            if (!_sendEmailEnabled)
            {
                return(string.Empty);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(email.From))
                {
                    email.From = _emailDefaultFrom;
                }

                if (string.IsNullOrWhiteSpace(email.To))
                {
                    email.To = _emailDefaultTo;
                }

                var message = new MailMessage
                {
                    From       = new MailAddress(email.From, email.FromName),
                    IsBodyHtml = email.IsHtml,
                    Subject    = email.Subject,
                    Body       = email.Body,
                };

                foreach (string addressTo in email.To.Split(';', ',').Where(e => !string.IsNullOrWhiteSpace(e)))
                {
                    message.To.Add(addressTo.Trim());
                }

                foreach (var attachs in email.Attachments.Where(at => at.FileStream.Length > default(long)))
                {
                    message.Attachments.Add(new Attachment(attachs.FileStream, attachs.FileNameWithExtension));
                }

                SmtpClient smtpClient = GetSmtpClient();
                smtpClient.Send(message);

                return(string.Empty);
            }
            catch (Exception ex)
            {
                return(ex.GetAllExceptionMessages());
            }
        }
Ejemplo n.º 7
0
        public JsonResult update(int id, BaseEmail model)
        {
            BoolString validation = model.BeforeEdit(db);

            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            validation = model.AfterEdit(db);
            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            return(Json(new { id = model.id, MessageSucess = "That Email saved successfully." }));
        }
Ejemplo n.º 8
0
        public JsonResult create(BaseEmail model)
        {
            BoolString validation = model.BeforeSave(db);

            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            db.BaseEmails.Add(model);
            db.SaveChanges();
            validation = model.AfterSave(db);
            if (validation.BoolValue)
            {
                return(Json(new { Message = validation.StringValue }));
            }
            return(Json(new { id = model.id, MessageSucess = "That Email saved successfully." }));
        }
 public JsonResult OnRegister(Register model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(Json(new { status = "error", message = $"Captcha is invalid!." }));
         }
         else if (db.BaseAccounts.Count(d => d.email == model.email) > 0)
         {
             return(Json(new { status = "error", message = $"This user already exists" }));
         }
         else if (db.BaseAccounts.Count(d => d.username == model.username) > 0)
         {
             return(Json(new { status = "error", message = $"This username already exists" }));
         }
         BaseAccount account = new BaseAccount();
         account.email        = model.email;
         account.fullName     = model.fullName;
         account.phone        = model.phone;
         account.username     = model.username;
         account.registered   = false;
         account.creationDate = DateTime.Now;
         account.password     = Permission.CalculateMD5Hash(model.password);
         account.token        = Permission.CalculateMD5Hash(account.creationDate.ToString() + model.email);
         db.BaseAccounts.Add(account);
         db.SaveChanges();
         SendMail mail = new SendMail();
         mail.To.Add(model.email);
         BaseEmail text = db.BaseEmails.FirstOrDefault(d => d.code == "Register");
         Dictionary <string, string> vars = new Dictionary <string, string>();
         vars.Add("@fullname@", model.fullName);
         var url = URLHelper.getAbsoluteUrlNoHome("BaseService", "ValidateAccount", new string[] { $"token={account.token}" });
         vars.Add("@link@", $"<a href={url}>here</a>");
         mail.Body    = Helper.ReplaceDictionary(text.bodyHTML, vars);
         mail.Subject = text.subject;
         mail.Send();
         return(Json(new { status = "success", message = $"Your account has been registered, check your mail for next steps" }));
     }
     catch (Exception ex)
     {
         return(Json(new { status = "error", message = ex.Message }));
     }
 }
Ejemplo n.º 10
0
        public JsonResult Save(BaseEmail model, FormCollection form)
        {
            try
            {
                if (model.id != 0)
                {
                    BoolString validation = model.BeforeEdit(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    validation = model.AfterEdit(db);

                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                }
                else
                {
                    BoolString validation = model.BeforeSave(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }

                    db.BaseEmails.Add(model);
                    db.SaveChanges();
                    validation = model.AfterSave(db);
                    if (validation.BoolValue)
                    {
                        return(Json(new { Message = validation.StringValue }));
                    }
                }
                return(Json(new { id = model.id, MessageSucess = "That Email saved successfully." }));
            }
            catch (Exception ex)
            {
                return(Json(new { Message = Helper.ModeralException(ex).Replace("@table", "Email") }));
            }
        }
        public ActionResult ValidateAccount(string token)
        {
            try
            {
                var account = db.BaseAccounts.FirstOrDefault(x => x.token == token && !x.registered);
                account.registered = true;
                db.SaveChanges();

                SendMail mail = new SendMail();
                mail.To.Add(account.email);
                BaseEmail text = db.BaseEmails.FirstOrDefault(d => d.code == "RegisterSuccess");
                Dictionary <string, string> vars = new Dictionary <string, string>();
                vars.Add("@fullname@", account.fullName);
                mail.Body    = Helper.ReplaceDictionary(text.bodyHTML, vars);
                mail.Subject = text.subject;
                mail.Send();
                WebSecurity.Login(account.email, account.password + "/force/force", persistCookie: false);
                return(RedirectToAction("Index", "Send"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Send"));
            }
        }
Ejemplo n.º 12
0
        private static async Task ProcessEmail(IAsyncCollector <SendGridMessage> emailProvider, ILogger log,
                                               BaseEmail topicMessage, CancellationToken token)
        {
            var message         = new SendGridMessage();
            var personalization = new Personalization();


            if (topicMessage.TemplateId != null)
            {
                message.Asm = new ASM
                {
                    GroupId = topicMessage.UnsubscribeGroup
                };
                message.TemplateId = topicMessage.TemplateId;
                message.Subject    = topicMessage.Subject;
                if (topicMessage.Campaign != null)
                {
                    message.AddCategory(topicMessage.Campaign);
                    message.TrackingSettings = new TrackingSettings
                    {
                        Ganalytics = new Ganalytics
                        {
                            UtmCampaign = topicMessage.Campaign,
                            UtmSource   = "SendGrid",
                            UtmMedium   = "Email",
                            Enable      = true
                        }
                    };
                    message.TrackingSettings.Ganalytics.Enable = true;
                }

                personalization.Substitutions = new Dictionary <string, string>();
                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(topicMessage))
                {
                    var p = prop.GetValue(topicMessage);
                    personalization.Substitutions[$"-{prop.Name}-"] = p?.ToString() ?? string.Empty;
                    //personalization.AddSubstitution($"-{prop.Name}-", p?.ToString() ?? string.Empty);
                }
                message.Personalizations = new List <Personalization>()
                {
                    personalization
                };
            }
            else
            {
                message.AddContent("text/html", topicMessage.ToString());
                message.Subject = topicMessage.Subject;
                if (topicMessage.Bcc != null)
                {
                    foreach (var bcc in topicMessage.Bcc)
                    {
                        message.AddBcc(bcc);
                    }
                }
                log.LogWarning("error with template name" + topicMessage.TemplateId);
            }

            CultureInfo.DefaultThreadCurrentCulture = topicMessage.Info;
            message.AddFromResource(topicMessage.Info);
            message.AddTo(topicMessage.To);

            await emailProvider.AddAsync(message, token);
        }
Ejemplo n.º 13
0
 public Task InsertMessageAsync(BaseEmail obj, CancellationToken token)
 {
     return(InsertMessageAsync(obj, TimeSpan.Zero, token));
 }
Ejemplo n.º 14
0
 protected Task SendEmail(BaseEmail obj, TimeSpan delay, CancellationToken token)
 {
     return(_serviceBusProvider.InsertMessageAsync(obj, delay, token));
 }