示例#1
0
        public override void DeleteNotificationAddress(string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentNullException("address", "ServerModel::DeleteNotificationAddress");
            }

            var deleteAddress = address.ToLowerInvariant();
            var notificationAddressSettings = NotificationAddressSettings.LoadForTenant(Tenant);

            if (notificationAddressSettings.NotificationAddress != deleteAddress)
            {
                throw new ArgumentException("Mailbox not exists");
            }

            _DeleteNotificationAddress(address);

            if (!(notificationAddressSettings.GetDefault() as NotificationAddressSettings).SaveForTenant(Tenant))
            {
                throw new Exception("Could not delete notification address setting.");
            }
        }
示例#2
0
        public override INotificationAddress CreateNotificationAddress(string localpart, string password, IWebDomain domain,
                                                                       IMailServerFactory factory)
        {
            if (string.IsNullOrEmpty(localpart))
            {
                throw new ArgumentNullException("localpart");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }

            if (localpart.Length + domain.Name.Length > 318) // 318 because of @ sign
            {
                throw new ArgumentException("Address of mailbox exceed limitation of 319 characters.", "localpart");
            }

            var notificationAddressBase = new MailAddressBase(localpart, new WebDomainBase(domain));

            var address = notificationAddressBase.ToString();

            var smtpSettings = TeamlabServerDal.GetTenantServerSettings().FirstOrDefault(s => s.type == ServerType.Smtp);

            if (smtpSettings == null)
            {
                throw new Exception("No smtp settings.");
            }

            var smtpLogin = smtpSettings.smtpLoginFormat.Replace("%EMAILADDRESS%", address)
                            .Replace("%EMAILLOCALPART%", localpart)
                            .Replace("%EMAILDOMAIN%", notificationAddressBase.Domain.Name.ToLowerInvariant())
                            .Replace("%EMAILHOSTNAME%", Path.GetFileNameWithoutExtension(notificationAddressBase.Domain.Name.ToLowerInvariant()));

            var notificationAddressSettings =
                SettingsManager.Instance.LoadSettings <NotificationAddressSettings>(Tenant);

            if (!string.IsNullOrEmpty(notificationAddressSettings.NotificationAddress))
            {
                throw new Exception("Setting already exists. Remove first.");
            }

            _CreateNotificationAddress(address, password, localpart, domain.Name);

            notificationAddressSettings = new NotificationAddressSettings {
                NotificationAddress = address
            };

            if (!SettingsManager.Instance.SaveSettings(notificationAddressSettings, Tenant))
            {
                _DeleteNotificationAddress(address);
                throw new Exception("Could not save notification address setting.");
            }

            var notificationAddress =
                factory.CreateNotificationAddress(localpart, domain, smtpSettings.hostname, smtpSettings.port,
                                                  smtpLogin,
                                                  true, smtpSettings.socket_type, smtpSettings.authentication_type);

            return(notificationAddress);
        }