Example #1
0
        /// <summary>
        /// Sends an e-mail (and creates an e-mail audit record).
        /// </summary>
        public static void SendEmail(MailMessage message, EmailCategory? category, int? relatedEntityID, int? userIdReceiver = null)
        {
            int? currentUserId = null;
            if (LogonUserDal.GetCurrentUser()!=null) {
                currentUserId = LogonUserDal.GetCurrentUser().Id;
            }

            EmailAuditDal emailAuditDal = new EmailAuditDal(message, category, currentUserId, userIdReceiver, relatedEntityID);

            SmtpClient smtpClient = new SmtpClient();

            // Try to send the mail.
            try {
                smtpClient.Send(message);

                // When the send succeeds set the status to send and set the time and date.
                emailAuditDal.EmailStatus = EmailStatus.Sent;
                emailAuditDal.DateSent = System.DateTime.Now;
            } catch (SmtpException e) {
                // When sending the mail fails set the status to sendError and set the status message.
                emailAuditDal.EmailStatus = EmailStatus.SendError;
                emailAuditDal.StatusMessage = string.Format("Fout bij het verzenden ('{0}').", e.Message);
            }

            emailAuditDal.Save();
        }
Example #2
0
        /// <summary>
        /// Constructor. Construct a mailaudit object based on a mailmessage object.
        /// </summary>
        /// <param name="mailMessage"></param>
        public EmailAuditDal(MailMessage mailMessage, EmailCategory? category, int? userIdSender, int? userIdReceiver, int? attachmentEntityID)
        {
            _emailAudit = new emailaudit();

            // Copy data from the MailMessage object to the MailAudit object.
            FromAddress = mailMessage.From.Address;
            ToAddresses = MailAddressesToString(mailMessage.To);
            CCAddresses = MailAddressesToString(mailMessage.CC);
            BccAddresses = MailAddressesToString(mailMessage.Bcc);
            Subject = mailMessage.Subject;
            Body = mailMessage.Body;
            IsHtml = mailMessage.IsBodyHtml;

            // Initialize the mailstatus to Unsent and set the creation date.
            EmailStatus = (int) EmailStatus.Unsent;
            DateCreated = System.DateTime.Now;

            // Set the mailcateogry and related entity (both can be null)
            if (category.HasValue) {
                EmailCategory = category.Value;
            }
            if (attachmentEntityID.HasValue) {
                AttachmentEntityId = attachmentEntityID.Value;
            }

            if (userIdReceiver.HasValue) {
                UserIdReceiver = userIdReceiver.Value;
            }

            if (userIdSender.HasValue) {
                UserIdSender = userIdSender.Value;
            }
        }
        public string ComposeConfirmationEmailURL(EmailCategory category, int eventId, int registrationId)
        {
            string url = string.Empty;
            string emailId = FetchConfirmationEmailId(category, eventId);
            string attendeeId = FetchAttendeeId(registrationId);

            url = ConfigReader.DefaultProvider.AccountConfiguration.BaseUrl +
                string.Format(ConfirmationEmailURLConstructor, eventId, AccessData.GetEncryptString(attendeeId), AccessData.GetEncryptString(emailId));

            return url;
        }
        public void ModifyEmailHtmlContent(EmailCategory category, string appendedContentText)
        {
            string content = DefaultConfirmationEmailHtmlContentAttribute.GetHtmlContent(category);

            if (!string.IsNullOrEmpty(appendedContentText))
            {
                content = content + "<p>" + appendedContentText + "</p>";
            }

            this.TypeContentInHTMLView(content);
        }
 public ActionResult Create(EmailCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         var country = new EmailCategory
         {
             Name         = model.Name,
             Published    = model.Published,
             DisplayOrder = model.DisplayOrder
         };
         _emailCategory.InsertEmailCategory(country);
         return(RedirectToAction("List"));
     }
     return(View(model));
 }
Example #6
0
        /// <summary>
        /// Sends an e-mail (and creates an e-mail audit record).
        /// </summary>
        public static void SendEmail(string to, string from, string cc, string bcc, string subject, string body, bool isBodyHtml, 
                                        EmailCategory? category, int? relatedEntityID, int? userIdReceiver, Attachment attachment)
        {
            string fromAddress = from ?? "*****@*****.**";
            MailMessage message = new MailMessage(fromAddress, to, subject, body);
            message.To.Add(new MailAddress(fromAddress, "karakterstructuren.com"));
            if (cc!=null) {
                message.CC.Add(cc);
            }
            if (bcc!=null) {
                message.Bcc.Add(bcc);
            }
            message.IsBodyHtml = isBodyHtml;
            message.To.Add(to);
            if (attachment != null) {
                message.Attachments.Add(attachment);
            }

            SendEmail(message, category, userIdReceiver, relatedEntityID);
        }
        public List <EmailCategory> getCategories()
        {
            var                  dbCategories = cateRepo.getAll();
            EmailCategory        category     = null;
            List <EmailCategory> cates        = new List <EmailCategory>();

            foreach (var cate in dbCategories)
            {
                category             = new EmailCategory();
                category.id          = cate.id;
                category.Name        = cate.Name;
                category.color       = cate.color;
                category.createddate = cate.createddate;
                category.creator     = cate.creator;
                category.description = cate.description;
                category.lastupdate  = category.lastupdate;
                cates.Add(category);
            }
            return(cates);
        }
Example #8
0
        private void UpdateUserAccountEmailType(ConfirmableUserAccount userAccount, IEnumerable <int> emailTypeIDs, bool sms)
        {
            using (DataContext dataContext = new DataContext("dbOpenXDA"))
            {
                // update links between user account and email type
                EmailCategory     eventEmailCategory            = dataContext.Table <EmailCategory>().QueryRecordWhere("Name = 'Event'");
                DataTable         userAccountEmailTypeDataTable = dataContext.Connection.RetrieveData(UserAccountEmailTypeQuery, userAccount.ID, eventEmailCategory.ID, sms);
                IEnumerable <int> userAccountEmailTypeIDs       = userAccountEmailTypeDataTable.Select().Select(x => (int)x["EmailTypeID"]);

                // formData will come back as null instead of empty array ....
                if (emailTypeIDs == null)
                {
                    emailTypeIDs = new List <int>();
                }

                // First pass. Add Link in database if the link does not exist.
                foreach (int id in emailTypeIDs)
                {
                    if (!userAccountEmailTypeIDs.Contains(id))
                    {
                        UserAccountEmailType userAccountEmailType = new UserAccountEmailType();
                        userAccountEmailType.UserAccountID = userAccount.ID;
                        userAccountEmailType.EmailTypeID   = id;
                        dataContext.Table <UserAccountEmailType>().AddNewRecord(userAccountEmailType);
                    }
                }

                userAccountEmailTypeDataTable = dataContext.Connection.RetrieveData(UserAccountEmailTypeQuery, userAccount.ID, eventEmailCategory.ID, sms);

                // Second pass. Remove Link if the link does not exist in data from form.
                foreach (DataRow link in userAccountEmailTypeDataTable.Rows)
                {
                    if (!emailTypeIDs.Contains((int)link["EmailTypeID"]))
                    {
                        dataContext.Table <UserAccountEmailType>().DeleteRecordWhere("ID = {0}", (int)link["UserAccountEmailTypeID"]);
                    }
                }
            }
        }
        public ActionResult EditTemplate(int id)
        {
            Email_Template dbTemplate = mailRepo.getById(id);

            EmailTemplateEntity template = new EmailTemplateEntity();

            template.Name        = dbTemplate.Name;
            template.MailContent = dbTemplate.MailContent;
            template.CateID      = dbTemplate.CateID;

            EmailCategory cate = new EmailCategory();

            cate.Name = cateRepo.getById((int)template.CateID).Name;


            var viewModel = new CreateEmailTemplateViewModel
            {
                EmailTemplateEntity = template,
                EmailCategories     = getCategories(),
                EmailCategory       = cate
            };

            return(View("EditTemplate", viewModel));
        }
 public string FetchConfirmationEmailId(EmailCategory category, int eventId)
 {
     int regMailTriggerId = RegMailTriggerIdAttribute.GetRegMailTriggerId(category);
     string emailId = string.Empty;
     var db = new DataAccess.ClientDataContext(ConfigReader.DefaultProvider.EnvironmentConfiguration.ClientDbConnection);
     var id = (from i in db.RegMailResponders where i.EventId == eventId && i.RegMailTypeId == 2 && i.RegMailTriggerId == regMailTriggerId orderby i.Id descending select i.Id).ToList();
     emailId = id[0].ToString();
     return emailId;
 }
 public static int GetRegMailTriggerId(EmailCategory category)
 {
     Type type = category.GetType();
     FieldInfo fi = type.GetField(category.ToString());
     RegMailTriggerIdAttribute[] attrs = fi.GetCustomAttributes(typeof(RegMailTriggerIdAttribute), false) as RegMailTriggerIdAttribute[];
     return attrs[0].TriggerId;
 }
 public static string GetHtmlContent(EmailCategory category)
 {
     Type type = category.GetType();
     FieldInfo fi = type.GetField(category.ToString());
     DefaultConfirmationEmailHtmlContentAttribute[] attrs = fi.GetCustomAttributes(typeof(DefaultConfirmationEmailHtmlContentAttribute), false) as DefaultConfirmationEmailHtmlContentAttribute[];
     return attrs[0].HtmlContent;
 }
 public void OpenConfirmationEmailUrl(EmailCategory category, int eventId, int registrationId)
 {
     string url = ComposeConfirmationEmailURL(category, eventId, registrationId);
     UIUtil.DefaultProvider.OpenUrl(url);
 }
 public ConfirmationEmailBody(EmailCategory category)
 {
     this.Category = category;
 }
Example #15
0
 public bool SendEmail(
     EmailCategory category,
     string subject,
     string body,
     List <string> attachmentFileNames,
     bool isHtml,
     List <EmailNotificationRecipient> emailRecipients,
     string logoImageFilePath,
     out string errorMessage,
     out string emailLogMessageText,
     bool appendHostNameToEmailBody)
 {
     if (!_emailNotificationsEnabled)
     {
         errorMessage        = $"{nameof(EmailNotificationsEnabled)} set to {false.ToString()}.";
         emailLogMessageText = string.Empty;
         return(false);
     }
     body = body ?? string.Empty;
     if (appendHostNameToEmailBody)
     {
         string        hostname   = Information.GetUserDomainAndMachineName();
         StringBuilder editedBody = new StringBuilder();
         editedBody.AppendLine(body);
         editedBody.AppendLine();
         editedBody.AppendLine($"Email originated from host: {hostname}");
         body = editedBody.ToString();
     }
     try
     {
         using (SmtpClient client = GetSmtpClient())
         {
             using (MailMessage email = GetMailMessage(subject, body, isHtml))
             {
                 if (_includeDefaultEmailRecipients && (_defaultEmailRecipients != null))
                 {
                     _defaultEmailRecipients.ForEach(p => AddRecipientToEmail(p.EmailAddress, p.DisplayName, email, EmailRecipientType.BCC));
                 }
                 if (emailRecipients != null)
                 {
                     emailRecipients.ForEach(p => AddRecipientToEmail(p.EmailAddress, p.DisplayName, email, EmailRecipientType.To));
                 }
                 List <MemoryStream> attachmentStreams = null;
                 try
                 {
                     if (attachmentFileNames != null)
                     {
                         attachmentStreams = new List <MemoryStream>();
                         AddAttachments(email, attachmentFileNames, attachmentStreams, logoImageFilePath, isHtml, body, out body);
                     }
                     client.Send(email);
                     LogEmailNotification(email, subject, out emailLogMessageText);
                 }
                 finally
                 {
                     if (attachmentStreams != null)
                     {
                         attachmentStreams.ForEach(p =>
                         {
                             p.Close();
                             p.Dispose();
                         });
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         if (_throwEmailFailExceptions)
         {
             throw;
         }
         errorMessage        = ex.Message;
         emailLogMessageText = string.Empty;
         ExceptionHandler.HandleException(ex, false, out errorMessage, out emailLogMessageText, null); //If emailing failed, then specify that the ExceptionHandler should not try to send the email exception as it would be futile and would result in overflow stack due to cyclic redundancy between ExceptionHandler and EmailClient.
         return(false);
     }
     errorMessage = null;
     return(true);
 }