protected void btn_SaveAccount_Click(object sender, EventArgs e) { string account = tb_Account.Text; string password = tb_Password.Value; string emailServer = ddl_EmailServer.SelectedValue; if (account.IsNullOrEmpty()) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('请输入邮箱账号!')", true); } if (password.IsNullOrEmpty()) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('请输入邮箱密码!')", true); } bool result = EmailAccountBusiness.SaveEmailAccount(Convert.ToInt32(uid), account, password, emailServer); if (result) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('保存成功!')", true); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('保存失败!')", true); } }
protected void btn_Add_Click(object sender, EventArgs e) { EmailAccount email = EmailAccountBusiness.GetEmailAccount(Convert.ToInt32(uid)); if (email == null) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('请先保存发件人的邮箱账号!')", true); return; } Response.Redirect("SendEmail_SelectPerson.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (uid == null) { Response.Redirect("../../LogInPage.aspx"); } if (!IsPostBack) { RefreshTable(0); EmailAccount email = EmailAccountBusiness.GetEmailAccount(Convert.ToInt32(uid)); if (email != null) { ddl_EmailServer.SelectedValue = email.EmailServer; tb_Account.Text = email.Account; tb_Password.Value = email.Password; tb_Password.Attributes.Add("value", "hgknight"); } } }
protected void btn_Send_Click(object sender, EventArgs e) { try { EmailAccount email = EmailAccountBusiness.GetEmailAccount(Convert.ToInt32(uid)); if (email == null) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "layer.alert('请先保存发件人的邮箱账号!')", true); return; } SmtpClient client = new SmtpClient(); client.Host = email.EmailServer;//"smtp.163.com"; client.UseDefaultCredentials = false; //发件人邮箱账号、密码 //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "zpc0622wangyi"); client.Credentials = new System.Net.NetworkCredential(email.Account, email.Password); client.DeliveryMethod = SmtpDeliveryMethod.Network; //发件人地址、收件人地址 MailMessage message = new MailMessage(email.Account, this.Label_MessageTo.Text.Trim()); //string To = this.Label_MessageTo.Text.Trim(); //message.To.Add(To); message.BodyEncoding = System.Text.Encoding.UTF8; //设置编码 message.IsBodyHtml = true; //设置正文为HTML格式 message.Subject = tb_Subject.Text.Trim(); message.Body = tb_Body.Text.Trim(); client.Send(message); DateTime createtime = DateTime.Now; string title = tb_Subject.Text.Trim(); string content = tb_Body.Text.Trim(); //新建邮件数据库记录 TEmail send_r = BusinessSupply.BusinessOper.EmailBusiness.AddEmail(0, Convert.ToInt32(uid), createtime, title, content); if (send_r != null) { //写入邮件人收件人数据库记录 //收件人personmemberid string[] temp_id = receiverid.Split(','); //收件人email地址 string[] temp_emailadress = receiver.Split(','); int emailid = send_r.Id; for (int j = 0; j < temp_id.Length; j++) { if (temp_emailadress[j] != "") { string a = BusinessSupply.BusinessOper.Email_PersonBusiness.AddEmail_Person(emailid, Convert.ToInt32(temp_id[j]), temp_emailadress[j]); if (a != "1") { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('发送失败!')", true); return; } } } ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('发送成功!')", true); } } catch { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('发送失败!')", true); } }