private void SendMailMessage(UserInfo user, IEnumerable <DomainInfo> domains, Dictionary <int, UserInfo> domainUsers, IEnumerable <DomainInfo> nonExistenDomains, bool includeNonExistenDomains)
        {
            BackgroundTask topTask = TaskManager.TopTask;

            UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.DOMAIN_EXPIRATION_LETTER);

            string from = settings["From"];

            var bcc = settings["CC"];

            string subject = settings["Subject"];
            string body    = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
            bool   isHtml  = user.HtmlMail;

            MailPriority priority = MailPriority.Normal;

            if (!String.IsNullOrEmpty(settings["Priority"]))
            {
                priority = (MailPriority)Enum.Parse(typeof(MailPriority), settings["Priority"], true);
            }

            // input parameters
            string mailTo = (string)topTask.GetParamValue("MAIL_TO");

            Hashtable items = new Hashtable();

            items["user"] = user;

            items["Domains"] = domains.Select(x => new { DomainName             = x.DomainName,
                                                         ExpirationDate         = x.ExpirationDate < DateTime.Now ? "Expired" : x.ExpirationDate.ToString(),
                                                         ExpirationDateOrdering = x.ExpirationDate,
                                                         Registrar = x.RegistrarName,
                                                         Customer  = string.Format("{0} {1}", domainUsers[x.PackageId].FirstName, domainUsers[x.PackageId].LastName) })
                               .OrderBy(x => x.ExpirationDateOrdering).ThenBy(x => x.Customer).ThenBy(x => x.DomainName);

            items["IncludeNonExistenDomains"] = includeNonExistenDomains;

            items["NonExistenDomains"] = nonExistenDomains.Select(x => new
            {
                DomainName = x.DomainName,
                Customer   = string.Format("{0} {1}", domainUsers[x.PackageId].FirstName, domainUsers[x.PackageId].LastName)
            }).OrderBy(x => x.Customer).ThenBy(x => x.DomainName);


            body = PackageController.EvaluateTemplate(body, items);

            // send mail message
            MailHelper.SendMessage(from, mailTo, bcc, subject, body, priority, isHtml);
        }
Exemple #2
0
        private void SendMailMessage(UserInfo user, IEnumerable <DomainDnsChanges> domainsChanges, Dictionary <int, UserInfo> domainUsers)
        {
            BackgroundTask topTask = TaskManager.TopTask;

            UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.DOMAIN_LOOKUP_LETTER);

            string from = settings["From"];

            var bcc = settings["CC"];

            string subject = settings["Subject"];

            MailPriority priority = MailPriority.Normal;

            if (!String.IsNullOrEmpty(settings["Priority"]))
            {
                priority = (MailPriority)Enum.Parse(typeof(MailPriority), settings["Priority"], true);
            }

            // input parameters
            string mailTo = (string)topTask.GetParamValue("MAIL_TO");

            string body   = string.Empty;
            bool   isHtml = user.HtmlMail;

            if (domainsChanges.Any())
            {
                body = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
            }
            else
            {
                body = user.HtmlMail ? settings["NoChangesHtmlBody"] : settings["NoChangesTextBody"];
            }

            Hashtable items = new Hashtable();

            items["user"]        = user;
            items["DomainUsers"] = domainUsers;
            items["Domains"]     = domainsChanges;

            body = PackageController.EvaluateTemplate(body, items);

            // send mail message
            MailHelper.SendMessage(from, mailTo, bcc, subject, body, priority, isHtml);
        }
        public static string EvaluateMailboxTemplate(string template, Organization org, int?accountId, int itemId)
        {
            OrganizationUser user = null;

            if (accountId.HasValue)
            {
                user = OrganizationController.GetAccount(itemId, accountId.Value);
            }

            Hashtable items = new Hashtable();

            items["Organization"] = org;

            if (user != null)
            {
                items["account"] = user;
            }

            return(PackageController.EvaluateTemplate(template, items));
        }
        public static int SendPasswordReminder(string username, string ip)
        {
            // place log record
            TaskManager.StartTask("USER", "SEND_REMINDER", username);
            TaskManager.WriteParameter("IP", ip);

            try
            {
                // try to get user from database
                UserInfoInternal user = GetUserInternally(username);
                if (user == null)
                {
                    TaskManager.WriteWarning("Account not found");
                    // Fix for item #273 (NGS-9)
                    //return BusinessErrorCodes.ERROR_USER_NOT_FOUND;
                    return(0);
                }

                UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.PASSWORD_REMINDER_LETTER);
                string       from     = settings["From"];
                string       cc       = settings["CC"];
                string       subject  = settings["Subject"];
                string       body     = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
                bool         isHtml   = user.HtmlMail;

                MailPriority priority = MailPriority.Normal;
                if (!String.IsNullOrEmpty(settings["Priority"]))
                {
                    priority = (MailPriority)Enum.Parse(typeof(MailPriority), settings["Priority"], true);
                }

                if (body == null || body == "")
                {
                    return(BusinessErrorCodes.ERROR_SETTINGS_PASSWORD_LETTER_EMPTY_BODY);
                }

                // One Time Password feature
                user.Password = OneTimePasswordHelper.SetOneTimePassword(user.UserId);

                // set template context items
                Hashtable items = new Hashtable();
                items["user"]  = user;
                items["Email"] = true;

                // get reseller details
                UserInfoInternal reseller = UserController.GetUser(user.OwnerId);
                if (reseller != null)
                {
                    items["reseller"] = new UserInfo(reseller);
                }

                subject = PackageController.EvaluateTemplate(subject, items);
                body    = PackageController.EvaluateTemplate(body, items);

                // send message
                MailHelper.SendMessage(from, user.Email, cc, subject, body, priority, isHtml);

                return(0);
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
        private static MailTemplate EvaluateOrganizationSummaryTemplate(ExchangeOrganization org)
        {
            #region create template context
            Hashtable items = new Hashtable();

            // add organization
            items["org"] = org;

            // add package information
            PackageInfo space = PackageController.GetPackage(org.PackageId);
            items["space"] = space;

            // add user information
            UserInfo user = UserController.GetUser(space.UserId);
            items["user"] = user;
            #endregion

            #region load template
            // load template settings
            UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.EXCHANGE_HOSTED_EDITION_ORGANIZATION_SUMMARY);
            if (settings == null)
            {
                return(null);
            }

            // create template
            MailTemplate template = new MailTemplate();

            // from
            template.From = settings["From"];

            // BCC
            template.Bcc = settings["CC"];

            // subject
            template.Subject = settings["Subject"];

            // body
            template.IsHtml = user.HtmlMail;
            string bodySetting = template.IsHtml ? "HtmlBody" : "TextBody";
            template.Body = settings[bodySetting];

            // priority
            string priority = settings["Priority"];
            template.Priority = String.IsNullOrEmpty(priority)
                ? MailPriority.Normal
                : (MailPriority)Enum.Parse(typeof(MailPriority), priority, true);
            #endregion

            #region evaluate template
            if (template.Subject != null)
            {
                template.Subject = PackageController.EvaluateTemplate(template.Subject, items);
            }

            if (template.Body != null)
            {
                template.Body = PackageController.EvaluateTemplate(template.Body, items);
            }
            #endregion

            return(template);
        }