/// <summary> /// 获取EmailConfig信息 /// </summary> /// <param name="sender">邮件发送者</param> /// <returns>邮件配置实体</returns> public EmailConfig GetEmailConfig() { EmailConfig emailConfig = null; SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, "SELECT emailAddress,emailPassword,emailServerAddress,emailServerPort FROM usta_EmailConfig"); while (dr.Read()) { emailConfig = new EmailConfig { emailAddress = dr["emailAddress"].ToString().Trim(), emailPassword = dr["emailPassword"].ToString().Trim(), emailServerAddress = dr["emailServerAddress"].ToString().Trim(), emailServerPort = int.Parse(dr["emailServerPort"].ToString().Trim()) }; } dr.Close(); conn.Close(); return emailConfig; }
/// <summary> /// 更新EmailConfig /// </summary> /// <param name="emailConfig">邮件配置实体</param> /// <returns>操作成功标号</returns> public int UpdateEmailConfig(EmailConfig emailConfig) { SqlParameter[] parameters = { new SqlParameter("@emailAddress", SqlDbType.NChar,50), new SqlParameter("@emailPassword", SqlDbType.NChar,50), new SqlParameter("@emailServerAddress", SqlDbType.NChar,50), new SqlParameter("@emailServerPort", SqlDbType.Int,4), new SqlParameter("@sender", SqlDbType.NChar,10)}; parameters[0].Value = emailConfig.emailAddress; parameters[1].Value = emailConfig.emailPassword; parameters[2].Value = emailConfig.emailServerAddress; parameters[3].Value = emailConfig.emailServerPort; parameters[4].Value = emailConfig.sender; SqlHelper.ExecuteNonQuery(conn, CommandType.Text, "UPDATE usta_EmailConfig SET emailAddress=@emailAddress,emailPassword=@emailPassword,emailServerAddress=@emailServerAddress, emailServerPort=@emailServerPort WHERE sender=@sender", parameters); return 1; }
//修改邮件配置信息 protected void btnMailCommit_Click(object sender, EventArgs e) { if (txtEmailAddress.Text.Trim().Length == 0 || txtpasswd.Text.Trim().Length == 0 || txtMailServer.Text.Trim().Length == 0 || txtMailServerPort.Text.Trim().Length == 0) { Javascript.GoHistory(-1, "邮件配置信息不能为空,请输入!", Page); } else { UserCookiesInfo user = BllOperationAboutUser.GetUserCookiesInfo(); DalOperationAboutEmail doae = new DalOperationAboutEmail(); EmailConfig emailconfig = new EmailConfig(); emailconfig.emailAddress = txtEmailAddress.Text.Trim(); emailconfig.emailPassword = txtpasswd.Text.Trim(); emailconfig.emailServerAddress = txtMailServer.Text.Trim(); emailconfig.emailServerPort = int.Parse(txtMailServerPort.Text.Trim()); emailconfig.sender = user.userName; try { doae.UpdateEmailConfig(emailconfig); Javascript.AlertAndRedirect("更新邮件配置信息成功!", "/Administrator/EmailManage.aspx?fragment=4", Page); } catch (Exception ex) { MongoDBLog.LogRecord(ex); Javascript.AlertAndRedirect("更新邮件配置信息失败!", "/Administrator/EmailManage.aspx?fragment=4", Page); } } }