private bool chkUserInfo(string userName, string userPwd, string userEmail) { bool result = false; ChkUtil chkUtil = new ChkUtil(); if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(userPwd) || String.IsNullOrEmpty(userEmail)) { msg = "请确认信息是否填写完整"; } else if (!chkUtil.validateUser(userName)) { msg = "用户名不规范(0-9 a-z 2-18个字符)"; } else if (!chkUtil.validateUser(userPwd)) { msg = "密码不规范(0-9 a-z 2-18个字符)"; } else if (!chkUtil.validateEmail(userEmail)) { msg = "请填写正确的邮件地址"; } else { result = true; } if (msg != "") { MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); msg = ""; } return(result); }
//测试发送 private void buttonSend_Click(object sender, EventArgs e) { String testTo = this.textBoxEmailAddress.Text.Trim(); string from = ""; string account = ""; string password = ""; string smtp = ""; string To = testTo; string replyTo = ""; string Body = ""; string Title = ""; string sendMsg = ""; string nickName = ""; ChkUtil chkUtil = new ChkUtil(); AddConfigDao addConfigDao = new AddConfigDao(); SendMail sendMail; if (chkUtil.validateEmail(testTo)) { DataTable fromDt = addConfigDao.loadFrom().Tables["efrom"]; int testCount = fromDt.Rows.Count; if (testCount > 20) { testCount = 20; } for (int i = 0; i < testCount; i++) { //发送邮件 from = fromDt.Rows[i]["fromAddress"].ToString(); account = fromDt.Rows[i]["account"].ToString(); password = fromDt.Rows[i]["pwd"].ToString(); smtp = fromDt.Rows[i]["smtp"].ToString();; replyTo = fromDt.Rows[i]["fromAddress"].ToString(); nickName = from.Substring(0, from.IndexOf("@")); Title = "恭喜您," + nickName + " 用户使用 邮件营销系统 测试成功"; Body = "<br/>您好!<br/>&hbsp; 感谢您使用‘钱龙邮件营销系统’您收到来自" + nickName + "的邮件,表示本系统运行良好~!<br/>如果您希望使用我们更加优秀的服务,请登录官方网站 http://www.qianlongsoft.com/ 。"; sendMail = new SendMail(from, account, password, smtp, To, Body, Title, replyTo); sendMsg += "使用 " + from + " -> " + sendMail.Send() + "\r\n"; } if (sendMsg.Equals("")) { sendMsg = "请确认您已经填写了发件人"; } MessageBox.Show(sendMsg, "提示:只会测试前20个发件人的发件箱", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("请输入正确的邮件地址", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 检查 /// </summary> /// <returns></returns> private Boolean check(string account, string password, string localDomain, string onlineDomain, string smtp, string smtpPort) { Boolean result = false; String msg = ""; if ("".Equals(account) || account == null) { msg = "账号不能为空,请填写登陆邮箱的账号"; } else if ("".Equals(password) || password == null) { msg = "邮箱密码不能为空,请填写邮箱的登陆密码"; } else if ("".Equals(smtp) || smtp == null) { msg = "邮箱服务器不能为空,如:smtp.bywei.cn"; } else if ("".Equals(smtpPort) || smtpPort == null) { msg = "邮箱服务器端口号不能为空,默认端口号为25"; } else { Boolean local = this.radioButtonLocal.Checked; Boolean online = this.radioButtonOnline.Checked; if (local) { //本地邮件服务器 if ("".Equals(localDomain) || localDomain == null) { msg = "邮箱后缀名不能为空"; } fromAddress = account + "@" + localDomain; ChkUtil chkUtil = new ChkUtil(); if (!chkUtil.validateEmail(fromAddress)) { msg = "邮箱后缀名或者用户名有误"; } no = "本地服务器"; domain = localDomain; //验证链接是否成功 state = "正常"; result = true; } else if (online) { //线上邮件服务器 fromAddress = onlineDomain; ChkUtil chkUtil = new ChkUtil(); if (!chkUtil.validateEmail(onlineDomain)) { msg = "邮箱填写有误"; } if ("localhost".Equals(smtp) || "127.0.0.1".Equals(smtp)) { msg = "邮件服务器填写错误"; } domain = "false"; //验证链接是否成功 state = "正常"; result = true; } } if (!msg.Equals("")) { MessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(result); }
//检查配置 private Boolean check(Config config, Boolean checkBoxProxy, String SendCycle, String ForwardCount, String SendThreadNum, String ThreadMillisecond, String DiySendNum, String FromSendNum, String FailedNum) { Boolean result = false; String msg = ""; ChkUtil chkUtil = new ChkUtil(); if (checkBoxProxy) { if ("".Equals(config.Proxy)) { msg = "如果您使用了代发邮件,请填写代发邮件地址"; } else if (!chkUtil.validateEmail(config.Proxy)) { msg = "请输入正确的回复邮箱地址"; } } if ("".Equals(config.SendType)) { msg = "请填写发送类型"; } if ("".Equals(config.NickName)) { msg = "请填写昵称"; } if ("".Equals(config.Replay)) { msg = "请填写回复地址"; } else if (!chkUtil.validateEmail(config.Replay)) { msg = "请输入正确的回复邮箱地址"; } if ("".Equals(config.InboxType)) { msg = "请填写收件邮箱"; } if ("".Equals(SendCycle)) { msg = "请输入发件周期"; if (!chkUtil.validateNum(SendCycle)) { msg = "输入的發件周期必须为数字"; } } if (!"".Equals(config.Forward)) { if ("".Equals(ForwardCount)) { msg = "请输入转发邮件周期"; } else if (!chkUtil.validateNum(ForwardCount)) { msg = "输入的线程转发邮件周期必须为数字"; } if (!chkUtil.validateEmail(config.Forward)) { msg = "请输入正确的转发邮件地址"; } } if ("".Equals(SendThreadNum)) { msg = "请输入线程数量"; } if (!chkUtil.validateNum(SendThreadNum)) { msg = "输入的线程数量必须为0-9的数字"; } if ("".Equals(config.StartTime.ToString())) { msg = "开始时间不能为空"; } if ("".Equals(config.EndTime.ToString())) { msg = "结束时间不能为空"; } if ("".Equals(ThreadMillisecond)) { msg = "线程间隔时间不能为空"; } if ("".Equals(DiySendNum)) { msg = "单次发送数量不能为空"; } if ("".Equals(FromSendNum)) { msg = "邮箱发送上限不能为空"; } if ("".Equals(FailedNum)) { msg = "失败后更换发件人数量不能为空"; } if (msg == "") { result = true; } else { MessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(result); }