Beispiel #1
0
        /// <summary>
        /// Send notification
        /// </summary>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="emailAccount">Email account</param>
        /// <param name="languageId">Language identifier</param>
        /// <param name="tokens">Tokens</param>
        /// <param name="toEmailAddress">Recipient email address</param>
        /// <param name="toName">Recipient name</param>
        /// <param name="attachmentFilePath">Attachment file path</param>
        /// <param name="attachmentFileName">Attachment file name</param>
        /// <param name="replyToEmailAddress">"Reply to" email</param>
        /// <param name="replyToName">"Reply to" name</param>
        /// <param name="fromEmail">Sender email. If specified, then it overrides passed "emailAccount" details</param>
        /// <param name="fromName">Sender name. If specified, then it overrides passed "emailAccount" details</param>
        /// <param name="subject">Subject. If specified, then it overrides subject of a message template</param>
        /// <returns>Queued email identifier</returns>
        public virtual int SendNotification(DNHMessageTemplate messageTemplate,
                                            EmailAccount emailAccount, int languageId, IEnumerable <Token> tokens,
                                            string toEmailAddress, string toName,
                                            string attachmentFilePath  = null, string attachmentFileName = null,
                                            string replyToEmailAddress = null, string replyToName        = null,
                                            string fromEmail           = null, string fromName = null, string subject = null)
        {
            if (messageTemplate == null)
            {
                throw new ArgumentNullException("messageTemplate");
            }

            if (emailAccount == null)
            {
                throw new ArgumentNullException("emailAccount");
            }
            Tokenizer _tokenizer = new Tokenizer(new MessageTemplatesSettings());
            //retrieve localized message template data
            var bcc = messageTemplate.BccEmailAddresses;

            if (String.IsNullOrEmpty(subject))
            {
                subject = messageTemplate.Subject;
            }
            var body = messageTemplate.Body;

            //Replace subject and body tokens
            var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
            var bodyReplaced    = _tokenizer.Replace(body, tokens, true);

            //limit name length
            toName = CommonHelper.EnsureMaximumLength(toName, 300);

            var email = new QueuedEmail
            {
                Priority           = QueuedEmailPriority.High,
                From               = !string.IsNullOrEmpty(fromEmail) ? fromEmail : emailAccount.Email,
                FromName           = !string.IsNullOrEmpty(fromName) ? fromName : emailAccount.DisplayName,
                To                 = toEmailAddress,
                ToName             = toName,
                ReplyTo            = replyToEmailAddress,
                ReplyToName        = replyToName,
                CC                 = string.Empty,
                Bcc                = bcc,
                Subject            = subjectReplaced,
                Body               = bodyReplaced,
                AttachmentFilePath = attachmentFilePath,
                AttachmentFileName = attachmentFileName,
                AttachedDownloadId = messageTemplate.AttachedDownloadId,
                CreatedOnUtc       = DateTime.UtcNow,
                ///EmailAccountId = emailAccount.Id,
                DontSendBeforeDateUtc = !messageTemplate.DelayBeforeSend.HasValue ? null
                    : (DateTime?)(DateTime.UtcNow + TimeSpan.FromHours(messageTemplate.DelayPeriod.ToHours(messageTemplate.DelayBeforeSend.Value)))
            };

            QueuedEmailManager.Add(email);
            return(email.Id);
        }
        public ContentResult SaveExcel(string item)
        {
            //string b = Request["item"];
            IEnumerable <QueuedEmail> objItemList = JsonConvert.DeserializeObject <IEnumerable <QueuedEmail> >(item);

            JsonObject obj = new JsonObject();

            obj.StatusCode = 200;
            obj.Message    = "The process is sucessed";
            foreach (QueuedEmail objitem in objItemList)
            {
                //default value
                //   objitem.CreatedUser = CurrentUser.UserName;
                objitem.CreatedDate = SystemConfig.CurrentDate;
                objitem.CompanyID   = CurrentUser.CompanyID;
                QueuedEmailManager.Add(objitem);
            }

            return(Content(JsonConvert.SerializeObject(obj), "application/json"));
        }
        public ActionResult Create(QueuedEmail model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.CompanyID = CurrentUser.CompanyID;

                    if (model.Id != 0)
                    {
                        //get default value
                        QueuedEmail objOldQueuedEmail = QueuedEmailManager.GetById(model.Id, CurrentUser.CompanyID);
                        if (objOldQueuedEmail != null)
                        {
                            model.CreatedDate = objOldQueuedEmail.CreatedDate;
                            model.CreatedUser = objOldQueuedEmail.CreatedUser;
                        }

                        QueuedEmailManager.Update(model);
                    }
                    else
                    {
                        // TODO: Add insert logic here
                        //   model.CreatedUser = CurrentUser.UserName;
                        model.CreatedDate = SystemConfig.CurrentDate;
                        QueuedEmailManager.Add(model);
                    }
                    return(View(ViewFolder + "list.cshtml", QueuedEmailManager.GetAll(CurrentUser.CompanyID)));
                }
            }
            catch (Exception ObjEx)
            {
                //LogHelper.AddLog(new IfindLog() { LinkUrl = Request.Url.AbsoluteUri, Exception = ObjEx.Message, Message = ObjEx.StackTrace });
                return(View(model));
            }
            return(View(model));
        }
 public void Add(QueuedEmail queuedEmail)
 {
     _manager.Add(queuedEmail);
 }