Ejemplo n.º 1
0
        public void Execute(IJobExecutionContext context)
        {
            // send emails - this would be called by the scheduler
            EmailSendManager esm = new EmailSendManager();

            esm.SendQueuedEmail();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get items from db and send emails
        /// </summary>
        /// <param name="query"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public static Task GetItemsAndSendEmailAsync(IEnumerable <CriminalPerson> query, string email)
        {
            return(Task.Run(async() =>
            {
                try
                {
                    //get query items from db
                    var items = query.ToArray();

                    //make pdf attachments
                    var attachments = items.Select(x => PdfSharpModule.MakePdf(x)).ToList();

                    //get MaxItemsPerRequest from config file
                    int maxItems = 0;
                    if (!(int.TryParse(System.Configuration.ConfigurationManager.AppSettings["MaxItemsPerEmail"], out maxItems) &&
                          maxItems > 0))
                    {
                        maxItems = MaxItemsPerEmail;
                    }

                    //async send email with attachments (max N items in email)
                    if (!attachments.Any())
                    {
                        await EmailSendManager.EmailSendAsync("No matches", email, "Criminal persons");
                    }
                    else
                    {
                        int part = 1;
                        int parts = attachments.Count / maxItems;
                        if (attachments.Count % maxItems > 0)
                        {
                            parts++;
                        }

                        while (attachments.Any())
                        {
                            var attachmentsInEmail = attachments.Take(maxItems).ToArray();
                            //delete from whole collection
                            for (int i = 0; i < attachmentsInEmail.Length; i++)
                            {
                                attachments.Remove(attachmentsInEmail[i]);
                            }

                            await EmailSendManager.EmailSendAsync(String.Format("Search results: {0}, part {1} of {2}", items.Length, part++, parts), email, "Criminal persons", attachmentsInEmail);
                        }
                    }

                    logger.Info("Succesfully sent emails to {0} with {1} attachments", email, items.Length);
                }
                catch (Exception ex)
                {
                    //log errors
                    logger.Error(ex);
                }
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validate input data
        /// </summary>
        /// <param name="searchParams"></param>
        /// <param name="maxItems"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public static Result ValidateInputData(SearchParams searchParams, int maxItems, string email)
        {
            var result = new Result();

            result.Error = string.Empty;

            if (searchParams == null)
            {
                throw new Exception("SearchParams is null; ");
            }

            if (!EmailSendManager.IsValidEmail(email))
            {
                throw new Exception(String.Format("Email ({0}) is invalid; ", email));
            }

            if (maxItems <= 0)
            {
                throw new Exception(String.Format("Max items ({0}) must be greater than 0 is invalid; ", email));
            }

            //these validate we have to do on front end!
            //it did only for test
            if (searchParams.StartAge.HasValue && searchParams.EndAge.HasValue &&
                searchParams.StartAge.Value > searchParams.EndAge.Value)
            {
                result.Error += "Start age more than end one; ";
            }

            if (searchParams.StartHeight.HasValue && searchParams.EndHeight.HasValue &&
                searchParams.StartHeight.Value > searchParams.EndHeight.Value)
            {
                result.Error += "Start height more than end one; ";
            }

            if (searchParams.StartWeight.HasValue && searchParams.EndWeight.HasValue &&
                searchParams.StartWeight.Value > searchParams.EndWeight.Value)
            {
                result.Error += "Start weight more than end one; ";
            }

            if (string.IsNullOrEmpty(result.Error))
            {
                result.Success = true;
            }

            return(result);
        }
 public Task SendAsync(IdentityMessage message)
 {
     return(EmailSendManager.EmailSendAsync(message.Body, message.Destination, message.Subject));
 }
Ejemplo n.º 5
0
        public void EmailSendAsyncTest()
        {
            var task = EmailSendManager.EmailSendAsync("test", "*****@*****.**", "test");

            task.Wait();
        }