public static bool SendEmail(string subject, string content, string email) { try { Model.SiteEmail m_em = Model.SiteEmail.GetModel(t => t.id != 0); MailMessage mailmessage = new MailMessage(); SmtpClient smtp = new SmtpClient(); smtp.Host = m_em.Smtp; smtp.Port = Convert.ToInt32(m_em.Port); smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential(m_em.Email, DESEncrypt.Decrypt(m_em.Emailpwd)); smtp.EnableSsl = false; mailmessage.To.Clear(); mailmessage.To.Add(email); mailmessage.From = new MailAddress(m_em.Email, m_em.Emailname, System.Text.Encoding.UTF8); mailmessage.Subject = subject; mailmessage.SubjectEncoding = System.Text.Encoding.UTF8; mailmessage.Body = content; mailmessage.IsBodyHtml = true; mailmessage.BodyEncoding = System.Text.Encoding.UTF8; mailmessage.Priority = MailPriority.High; smtp.Send(mailmessage); } catch (Exception ex) { ExceptionEx.MyExceptionLog.AddLogError("发送邮件出错:" + ex.Message); return(false); } return(true); }
/// <summary> /// 添加/编辑 /// </summary> /// <param name="isEdit"></param> /// <param name="p_SiteEmail"></param> public void AESiteEmail(DealMvc.ControllerBase _CB, bool isEdit, ref Model.SiteEmail p_se) { Model.SiteEmail m_se = null; if (isEdit) { m_se = DealMvc.Model.SiteEmail.GetModel(p_se.id ?? 0); } else { m_se = new Model.SiteEmail(); } if (!isEdit) { if (Orm.EntityCore <Model.SiteEmail> .Exists("=id", new object[] { p_se.id })) { throw new ExceptionEx.MyExceptionMessageBox("已经存在此记录"); } } else { } m_se.Smtp = p_se.Smtp; //Smtp[Type=string] - 邮箱SMTP m_se.Emailname = p_se.Emailname; //Emailname[Type=string] - 用户帐号 m_se.Email = p_se.Email; //Email[Type=string] - 邮箱地址 m_se.Emailpwd = p_se.Emailpwd; //Emailpwd[Type=string] - 邮箱密码 m_se.Port = p_se.Port ?? 0; //Port[Type= int?] - 邮箱发送端口 m_se.IsRegSendEmail = p_se.IsRegSendEmail; //IsRegSendEmail[Type=bool] - 是否开启 m_se.UpTime = p_se.UpTime ?? DateTime.Now; //UpTime[Type=DateTime?] - 更新时间 p_se = m_se; if (isEdit) { m_se.Update(); ExceptionEx.MyExceptionLog.AlertMessage(_CB, "修改网站邮箱信息成功"); _CB.IsSaveForm = true; } else { m_se.Add(); ExceptionEx.MyExceptionLog.AlertMessage(_CB, "添加成功", true); } }