private void SaveEmailSettings() { MessageDisplay msgDisplay = CreateMessageDisplay("smtpserver","SmtpServerAccount","SmtpServerPassword","SenderEmail","Port"); int line = 0; EmailSendServerCollection emails = new EmailSendServerCollection(); int[] emailIDs = _Request.GetList<int>("emailids", Method.Post, new int[0]); EmailSettings settings = new EmailSettings(); bool enableSend = _Request.Get<bool>("EnableSendEmail", Method.Post, false); if (enableSend) { foreach (int i in emailIDs) { bool isnew = _Request.Get<bool>("isnew." + i, Method.Post, false); string keysubfix = isnew ? ".new." + i : "." + i; EmailSendServer email = new EmailSendServer(); email.EmailID = i; email.SmtpServer = _Request.Get("smtpserver" + keysubfix, Method.Post); email.SmtpServerAccount = _Request.Get("SmtpServerAccount" + keysubfix, Method.Post); email.SmtpServerPassword = _Request.Get("SmtpServerPassword" + keysubfix, Method.Post); email.SenderEmail =_Request.Get("senderemail"+keysubfix,Method.Post); email.EnableSSL = _Request.Get<bool>("EnableSSL" + keysubfix, Method.Post, false); email.Port = _Request.Get<int>("Port" + keysubfix, Method.Post,0); ValidateEmail(email,msgDisplay,line); emails.Add(email); line++; } settings.SendServers = emails; if (emails.Count == 0) { msgDisplay.AddError(new CustomError("开启邮件发送功能时至少填写一个Email帐号")); } } else { settings.SendServers = AllSettings.Current.EmailSettings.SendServers; } settings.EnableSendEmail = enableSend; if (!msgDisplay.HasAnyError()) { SettingManager.SaveSettings(settings); } m_Emails = settings.SendServers; }
public static void ConvertEmailSettingsAndKeywords() { string sql = @" IF EXISTS (SELECT * FROM sysobjects WHERE [type] = N'U' AND [name] = N'System_Max_Settings') BEGIN SELECT * FROM System_Max_Settings WHERE Catalog='EmailSetting' OR Catalog='KeywordSetting'; END ELSE SELECT '' AS SettingKey; "; EmailSettings setting = new EmailSettings(); EmailSendServer server = new EmailSendServer(); setting.SendServers.Add(server); ContentKeywordSettings keywordsetting = new ContentKeywordSettings(); using (SqlConnection connection = new SqlConnection(Settings.Current.IConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sql, connection); command.CommandTimeout = 60; try { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string key = reader.GetString(reader.GetOrdinal("SettingKey")); if (key == string.Empty) return; string value = reader.GetString(reader.GetOrdinal("SettingValue")); switch (key.ToLower()) { case "emailaddress": server.SenderEmail = value; break; case "openemail": setting.EnableSendEmail = (value.ToLower() == "true"); break; case "stmpserver": server.SmtpServer = value; break; case "stmpserverpassword": server.SmtpServerPassword = value; break; case "stmpserverusername": server.SmtpServerAccount = value; break; case "denykeywords": keywordsetting.BannedKeywords = new KeywordRegulation(); keywordsetting.BannedKeywords.SetValue(value); break; case "requireapprovedkeywords": keywordsetting.ApprovedKeywords = new KeywordRegulation(); keywordsetting.ApprovedKeywords.SetValue(value); break; case "replacekeywords": keywordsetting.ReplaceKeywords = new KeywordReplaceRegulation(); keywordsetting.ReplaceKeywords.SetValue(value); break; default: break; } } } server.Port = 25; sql = @" UPDATE bx_Settings SET [Value] = @SettingString WHERE TypeName = 'MaxLabs.bbsMax.Settings.EmailSettings' AND [Key] = '*'; IF @@ROWCOUNT = 0 INSERT INTO bx_Settings ([Key], [Value], [TypeName]) VALUES ('*', @SettingString, 'MaxLabs.bbsMax.Settings.EmailSettings'); UPDATE bx_Settings SET [Value] = @KeywordSettingString WHERE TypeName = 'MaxLabs.bbsMax.Settings.ContentKeywordSettings' AND [Key] = '*'; IF @@ROWCOUNT = 0 INSERT INTO bx_Settings ([Key], [Value], [TypeName]) VALUES ('*', @KeywordSettingString, 'MaxLabs.bbsMax.Settings.ContentKeywordSettings'); "; command.CommandText = sql; SqlParameter param = new SqlParameter("@SettingString", SqlDbType.NText); param.Value = setting.ToString(); command.Parameters.Add(param); SqlParameter param2 = new SqlParameter("@KeywordSettingString", SqlDbType.NText); param2.Value = keywordsetting.ToString(); command.Parameters.Add(param2); command.ExecuteNonQuery(); } catch (Exception ex) { CreateLog(ex); throw new Exception("����Emailϵͳ���úؼ�������ʧ��" + ex.Message + sql); } finally { connection.Close(); } } }