public IHttpActionResult ReSendEmail([FromUri] ResendEmail parameters)
        {
            if (!VerificationEmail(parameters.Email, parameters.ActivationCode, parameters.Password))
            {
                return(Content(HttpStatusCode.BadRequest, "Mail couldn't be sent but the users account has been created.<br>Click <a href='UserAccounts/ReSendEmail?email=" + parameters.Email + "&activationCode=" + parameters.ActivationCode.ToString() + "&password="******"' target='_blank'><b>here</b></a> to resend mail<br/>Be sure to check your Internet Connection"));
            }

            return(Content(HttpStatusCode.OK, "<p class='alert alert-success'>Your email has sent successfully</p>"));
        }
Example #2
0
        private void UpdateStatus(EmailStatus status, ResendEmail email, XElement errors)
        {
            int count = 0;

            while (true)
            {
                try
                {
                    using (EmailBounceBackDataContext ctx = new EmailBounceBackDataContext())
                    {
                        var eml = ctx.ResendEmails.Single(e => e.EmailID == email.EmailID);

                        if (status == EmailStatus.InProgress)
                        {
                            eml.InProgress = true;
                            eml.StartTime  = DateTime.Now;
                            eml.EndTime    = null;
                        }
                        else
                        {
                            eml.Status     = status.ToString();
                            eml.RetryCount = eml.RetryCount.GetValueOrDefault() + 1;
                            eml.EndTime    = DateTime.Now;
                            eml.InProgress = null;
                            eml.Errors     = errors;
                        }

                        ctx.SubmitChanges();
                    }

                    break;
                }
                catch (Exception e)
                {
                    // Increment the retry counter
                    count++;

                    // Log the exception
                    //ConfigLogger.Instance.Log(count < 5 ? LogSeverity.Warning : LogSeverity.Error, email.EmailID, e);
                    LogProvider.Log(GetType()).Error(e);
                    // Retry up to 5 times
                    if (count >= 5)
                    {
                        break;
                    }

                    // Sleep for a fraction
                    Thread.Sleep(50);
                }
            }
        }
Example #3
0
        public void ResendEmail(ResendEmail email)
        {
            // Throttle throughput
            //while (Queued >= Settings.ConcurrencyLevel)
            //{
            //    if (!timer.Enabled)
            //        break;

            //    Thread.Sleep(100);
            //}
            //if (!timer.Enabled)
            //    break;
            LogProvider.Log(GetType()).Info(String.Format("Processing Email-ID {0}...", email.EmailID));

            // Can't proceed if the mailbox profile isn't found
            if (!Settings.MailboxProfiles.ContainsKey(email.MailboxGUID.GetValueOrDefault()))
            {
                var message = email.MailboxGUID.HasValue ? String.Format("Mailbox Profile not found (MailboxGUID = {0}).", email.MailboxGUID) : "Mailbox Profile not found.";

                // Log the error
                LogProvider.Log(GetType()).Error(message);

                // Update the email status
                UpdateStatus(EmailStatus.Error, email, GetErrorXml(message, "Escalate", false));
            }
            else
            {
                // Get the mailbox profile required for the conversion
                var profile = Settings.MailboxProfiles[email.MailboxGUID.Value];

                //Resend email to default
                Emailer emailer = new Emailer(profile.ImapHost, profile.ImapPort);
                using (EmailBounceBackController controller = new EmailBounceBackController())
                {
                    UpdateStatus(EmailStatus.InProgress, email);
                    var fromaddress = controller.getSettingValue("Email_From", profile.ConnectionString);
                    var toaddress   = controller.getSettingValue("DefaultMailbox", profile.ConnectionString);
                    //ADD resend to subject
                    var ResendEmailSubject = email.OriginalEmailSubject.Insert(email.OriginalEmailSubject.IndexOf('(') + 1, "RESEND-");
                    var ResendEmailBody    = controller.getSettingValue("Dripfeed_Email_Body", profile.ConnectionString);
                    try
                    {
                        emailer.SendEmail(fromaddress
                                          , toaddress
                                          , ResendEmailSubject
                                          , ResendEmailBody
                                          , Directory.GetFiles(Path.GetDirectoryName(email.OriginalDocumentPath), Path.GetFileName(email.OriginalDocumentPath)));
                    }
                    catch (SmtpException ex)
                    {
                        //Connection Failure
                        // Create the error xml based on the exception thrown
                        var message = RemoveInvalidXmlChars(ex.ToString());
                        UpdateStatus(EmailStatus.Error, email, GetErrorXml(message, "Retry", true));
                    }
                    catch (Exception ex)
                    {
                        // Create the error xml based on the exception thrown
                        var message = RemoveInvalidXmlChars(ex.ToString());
                        UpdateStatus(EmailStatus.Error, email, GetErrorXml(message, "Retry", true));
                    }
                    finally
                    {
                        Interlocked.Increment(ref count);
                    }
                }
            }
        }
Example #4
0
 private void UpdateStatus(EmailStatus status, ResendEmail email)
 {
     UpdateStatus(status, email, null);
 }
Example #5
0
        private int DownloadEmail(Imap imap, MailProfile profile)
        {
            int count = 0;
            // Build the MailQuery
            var query = new MailQuery("('Deleted' = 'False')");

            var messages = imap.ListMessages(query);

            foreach (var message in messages)
            {
                MailMessage msg = null;

                msg = imap.FetchMessage(message.UniqueId);
                var filtertext = Properties.Settings.Default.Filtertext.Split(',').Where(x => x.Trim().Length > 0);
                if (filtertext.Any(x => msg.Subject.ToLower().Trim().Contains(x.ToLower().Trim())))
                {
                    LogProvider.Log(GetType()).Info(string.Format("Bounce Message Found : {0} Subject contains filter text : {1}", msg.Subject, filtertext.Any(x => msg.Subject.ToLower().Contains(x.ToLower()))));
                    //if a message is found check subject has documentid
                    LogProvider.Log(GetType()).Debug("Validating Mail Subject");
                    if (msg.Subject.ToLower().IndexOf("(resend") > 0)
                    {
                    }
                    else if (msg.Subject.IndexOf('(') > 0)
                    {
                        int DocumentID = Convert.ToInt32(msg.Subject.Substring(msg.Subject.IndexOf('(') + 1, msg.Subject.IndexOf(')') - msg.Subject.IndexOf('(') - 1));
                        if (Validate(DocumentID, profile.ConnectionString))
                        {
                            LogProvider.Log(GetType()).Info(string.Format("Message with Document ID {0} found in origin system", DocumentID));
                            //insert in table for document to be resend
                            using (EmailBounceBackController controller = new EmailBounceBackController())
                            {
                                ResendEmail dr = new ResendEmail()
                                {
                                    MessageID            = msg.MessageId,
                                    Subject              = msg.Subject,
                                    DocumentID           = DocumentID,
                                    OriginalDocumentPath = controller.getDocumentPath(DocumentID, profile.ConnectionString),
                                    OriginalEmailSubject = controller.getDocumentSubject(DocumentID, profile.ConnectionString),
                                    TimeStamp            = DateTime.Now
                                };
                                controller.InsertDocumentResend(dr);
                            }
                        }

                        // Move the email to the archive (if this fails, but the download is complete this
                        // will just result in a duplicate next time round if the deleted flag is not set)
                        imap.MoveMessage(message.UniqueId, "ResendArchive", true, false);
                        // Increment the download count
                        count++;
                    }
                    else
                    { //The message is not undeliverable or automated response, move to Archive so it will not be picked agian
                        imap.MoveMessage(message.UniqueId, "Archive", true, false);
                    }
                }
                else
                {
                    //The message is not undeliverable or automated response, move to Archive so it will not be picked agian
                    imap.MoveMessage(message.UniqueId, "Archive", true, false);
                }
            }
            return(count);
        }