示例#1
0
        public async Task <HttpResponseMessage> PostEmailMyWonders([FromBody] AuthModel authModel)
        {
            try
            {
                if (authModel.Password.Equals("SendMyWonderEmails"))
                {
                    //Check time of last send
                    var oneweekAgo = DateTime.Now.Subtract(new TimeSpan(6, 0, 0, 0));

                    if (DataContext.NotificationEmails.Any() && DataContext.NotificationEmails.Any(e => e.Sent > oneweekAgo))
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "No need to run yet"));
                    }

                    //TODO - inject dependent on email provider
                    var emailService = new Core.Services.EmailService(DataContext);

                    await emailService.SendMyWonderEmails();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }

                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "You are not authorized to execute this command"));
                }
            }


            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public bool Send(string to, bool isHtml = false, string cc = null, string bcc = null, List <string> Attachments = null, string userId = null)
        {
            Core.Services.EmailService emailService = new Core.Services.EmailService();
            emailService.Subject = this.subject;
            emailService.Message = this.message;
            emailService.Send(to, isHtml, cc, bcc, Attachments);
            // log to emailLogInternal table
            EmailModelContext     db       = new EmailModelContext();
            EmailInternalLogModel emailLog = new EmailInternalLogModel
            {
                SentTo   = to,
                SentCC   = cc,
                SentBCC  = bcc,
                SentDate = DateTime.Now,
                Subject  = subject,
                Body     = message
            };

            db.EmailInternalLogs.Add(emailLog);
            if (string.IsNullOrEmpty(userId))
            {
                db.SaveChanges();
            }
            else
            {
                db.SaveChanges(userId);
            }
            return(true);
        }
示例#3
0
        public async Task <HttpResponseMessage> ForceEmailMyWonders(string userId)
        {
            try
            {
                var user = DataContext.AspNetUsers.SingleOrDefault(u => u.Id == userId);

                if (user == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NoContent));
                }

                var emailService = new Core.Services.EmailService(DataContext);

                await emailService.CreateMyWondersEmailAndSend(user);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
 private async Task SendNotificationMail(int notificationId, NotificationType notificationType)
 {
     if (notificationType == NotificationType.ReportCreated ||
         notificationType == NotificationType.AssignedForReport)
     {
         var emailService = new Core.Services.EmailService();
         await emailService.SendNotificationMailAsync(await GetNotification(notificationId), EmailTemplateMappings.GetEmailTemplate("Notification")).WithoutSync();
     }
 }