示例#1
0
 public static void DeleteEmails(Guid loginId, String email)
 {
     using (EmailTableAdapter adapter = new EmailTableAdapter())
     {
         adapter.Delete(loginId, email);
     }
 }
        private void UpdateEmail(Email email)
        {
            if (email == null || email.Id <= 0)
            {
                throw new ArgumentException("Could not update email - email is null or has invalid id");
            }
            EmailTableAdapter adapter = new EmailTableAdapter();

            EmailData.EmailDataTable table = adapter.GetEmail(email.Id);
            if (table.Count == 0)
            {
                throw new ArgumentException(string.Format("Could not update email - email does not exist emailId=[{0}]", email.Id));
            }
            EmailData.EmailRow row = table[0];
            row.FailedAttempts = email.FailAttempts;
            if (email.FailedDate != null)
            {
                row.FailedDate = (DateTime)email.FailedDate;
            }
            row.FailedException = email.FailedException;
            if (email.SendDate != null)
            {
                row.SendDate = (DateTime)email.SendDate;
            }
            row.SendStatus = email.SendingStatus.ToString();
            adapter.Update(row);
        }
示例#3
0
 public static void InsertEmail(string email, Guid loginId)
 {
     using (EmailTableAdapter adapter = new EmailTableAdapter())
     {
         adapter.Insert(email, loginId);
     }
 }
示例#4
0
 public static MasterDataSet.EmailDataTable GetEmails(Guid loginId)
 {
     using (EmailTableAdapter adapter = new EmailTableAdapter())
     {
         return(adapter.GetEmails(loginId));
     }
 }
示例#5
0
 public static MasterDataSet.EmailDataTable GetEmail(string email)
 {
     using (EmailTableAdapter adapter = new EmailTableAdapter())
     {
         return(adapter.GetEmail(email));
     }
 }
        public List <Email> FindEmails(DateTime fromDate, DateTime toDate)
        {
            List <Email>      emails  = new List <Email>();
            EmailTableAdapter adapter = new EmailTableAdapter();

            EmailData.EmailDataTable table = adapter.FindEmails(fromDate, toDate);
            foreach (EmailData.EmailRow row in table)
            {
                emails.Add(EmailerHelper.ToEmailDTO(row, GetEmailAccountByEmailAddress(row.FromEmailAddress), GetEmailAttachments(row.Id)));
            }
            return(emails);
        }
        public List <Email> GetEmailsByBatch(string batchId)
        {
            List <Email>      emails  = new List <Email>();
            EmailTableAdapter adapter = new EmailTableAdapter();

            EmailData.EmailDataTable table = adapter.GetEmailsByBatchId(batchId);
            foreach (EmailData.EmailRow row in table)
            {
                emails.Add(EmailerHelper.ToEmailDTO(row, GetEmailAccountByEmailAddress(row.FromEmailAddress), GetEmailAttachments(row.Id)));
            }
            return(emails);
        }
        private void Save(Email newEmail)
        {
            try
            {
                if (newEmail == null)
                {
                    throw new ArgumentException("Could not save email - email object is null!");
                }
                EmailTableAdapter adapter = new EmailTableAdapter();
                if (string.IsNullOrEmpty(newEmail.CreatedBy))
                {
                    newEmail.CreatedBy = "SYSTEM";
                }
                string to      = string.Join(";", (from t in newEmail.To select t.EmailAddress).ToArray());
                int?   emailId = 0;
                adapter.Insert(newEmail.Guid,
                               newEmail.BatchId,
                               to,
                               newEmail.From.EmailAddress,
                               newEmail.From.DisplayName,
                               newEmail.Subject,
                               newEmail.Message,
                               newEmail.IsHtml,
                               DateTime.Now,
                               "",
                               0,
                               DateTime.Now,
                               newEmail.IsSigned,
                               newEmail.IsEncrypted,
                               newEmail.SendingStatus.ToString(),
                               newEmail.CreatedBy,
                               ref emailId);

                newEmail.Id = (int)emailId;

                foreach (EmailAttachment attach in newEmail.Attachments)
                {
                    SaveAttachment(newEmail.Id, attach);
                }
            }
            catch (Exception ex)
            {
                if (newEmail == null)
                {
                    _logger.Error(this.GetType(), ex, "Failed saving email.");
                }
                else
                {
                    _logger.Error(this.GetType(), ex, "Failed saving email id=[{0}] to=[{1}] subject=[{2}]", newEmail.Id, newEmail.To.ToString(), newEmail.Subject);
                }
            }
        }
        public Email GetEmail(int emailId)
        {
            if (emailId <= 0)
            {
                return(null);
            }
            EmailTableAdapter adapter = new EmailTableAdapter();

            EmailData.EmailDataTable table = adapter.GetEmail(emailId);
            if (table.Count == 0)
            {
                return(null);
            }
            EmailData.EmailRow row = table[0];
            return(EmailerHelper.ToEmailDTO(row, GetEmailAccountByEmailAddress(row.FromEmailAddress), GetEmailAttachments(row.Id)));
        }
        public void UpdateEmailStatus(int id, EmailSendStatus status, string lastEditedBy)
        {
            if (id == 0)
            {
                throw new ArgumentException(string.Format("Could not update email status - invalid email [{0}].", id));
            }
            EmailTableAdapter adapter = new EmailTableAdapter();

            EmailData.EmailDataTable table = adapter.GetEmail(id);
            if (table.Count == 0)
            {
                throw new ArgumentException(string.Format("Could not update email - email does not exist emailId=[{0}]", id));
            }
            EmailData.EmailRow row = table[0];
            row.SendStatus = status.ToString();
            adapter.Update(row);
        }
        public void InitDatabaseSchema()
        {
            var commands = new string[0];

            using (var script = new System.IO.StreamReader(this.GetType().Assembly.GetManifestResourceStream(this.GetType().Assembly.GetName().Name + ".MailBeeEmailerWithSqlBackup.sql")))
            {
                commands = script.ReadToEnd().Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);
            }

            using (var adapter = new EmailTableAdapter())
            {
                adapter.Connection.Open();

                var cmd = adapter.Connection.CreateCommand();

                foreach (var command in commands)
                {
                    cmd.CommandText = command;
                    cmd.ExecuteNonQuery();
                }
            }
        }