Beispiel #1
0
        /// <summary>
        /// /发送邮件的方法
        /// </summary>
        private static void SendMail(Entity.Mail mail, string ToWhere)
        {
            SmtpClient client = new SmtpClient(SMTP);                                                      //设置邮件协议

            client.UseDefaultCredentials = false;                                                          //这一句得写前面

            client.DeliveryMethod = SmtpDeliveryMethod.Network;                                            //通过网络发送到Smtp服务器

            client.Credentials = new NetworkCredential(Account, Pass);                                     //通过用户名和密码 认证

            MailMessage mmsg = new MailMessage(new MailAddress(Account), new MailAddress(ToWhere.Trim())); //发件人和收件人的邮箱地址

            mmsg.Subject = mail.title;                                                                     //邮件主题

            mmsg.SubjectEncoding = Encoding.UTF8;                                                          //主题编码

            mmsg.Body = mail.text;                                                                         //邮件正文

            mmsg.BodyEncoding = Encoding.UTF8;                                                             //正文编码

            mmsg.IsBodyHtml = true;                                                                        //设置为HTML格式

            mmsg.Priority = MailPriority.High;                                                             //优先级
            try

            {
                client.Send(mmsg);
            }
            catch (Exception ex)
            {
                throw new Entity.HrmException(ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// /发送邮件的方法
        /// </summary>
        public static void SendMail(string ToWhere, string pass)
        {
            Entity.Mail mm     = LoadMail();
            SmtpClient  client = new SmtpClient(mm.url);                                               //设置邮件协议

            client.UseDefaultCredentials = false;                                                      //这一句得写前面

            client.DeliveryMethod = SmtpDeliveryMethod.Network;                                        //通过网络发送到Smtp服务器

            client.Credentials = new NetworkCredential(mm.account, mm.pass);                           //通过用户名和密码 认证

            MailMessage mmsg = new MailMessage(new MailAddress(mm.account), new MailAddress(ToWhere)); //发件人和收件人的邮箱地址

            mmsg.Subject = "系统密码找回";                                                                   //邮件主题

            mmsg.SubjectEncoding = Encoding.UTF8;                                                      //主题编码

            mmsg.Body = "新的登陆密码为:" + pass + "请登陆后及时修改!";                                               //邮件正文

            mmsg.BodyEncoding = Encoding.UTF8;                                                         //正文编码

            mmsg.IsBodyHtml = true;                                                                    //设置为HTML格式

            mmsg.Priority = MailPriority.High;                                                         //优先级
            try

            {
                client.Send(mmsg);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 加载发送邮件服务器配置信息
 /// </summary>
 private static void LoadSendMailSet()
 {
     Entity.Mail m = BLL.FileUse.OpenMailSet("MailSet");
     Account = m.account.Trim();;
     Pass    = m.pass.Trim();
     SMTP    = m.url.Trim();
 }
Beispiel #4
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                //主设置
                Entity.Mail mail1 = new Entity.Mail();
                mail1.url     = this.txt_smtp1.Text;
                mail1.port    = int.Parse(this.txt_smtpk1.Text);
                mail1.account = this.txt_id1.Text;
                mail1.pass    = this.txt_pass1.Text;
                BLL.FileUse.SaveMailSet(mail1, "MailSet");
                //备用设置
                Entity.Mail mail2 = new Entity.Mail();
                mail2.url     = this.txt_smtp2.Text;
                mail2.port    = int.Parse(this.txt_smtpk2.Text);
                mail2.account = this.txt_id2.Text;
                mail2.pass    = this.txt_pass2.Text;
                BLL.FileUse.SaveMailSet(mail2, "BackMail");
            }
            catch (Entity.HrmException he)
            {
                Msg.Box.Show(he.Message);
                return;
            }

            Msg.Box.Show("恭喜您,配置保存成功!");
            LoadSet();
        }
Beispiel #5
0
        /// <summary>
        /// 保存邮件主配置
        /// </summary>
        /// <returns></returns>
        public static void SaveMailSet(Entity.Mail mail, string name)
        {
            FileStream      fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config\" + name + ".XML", FileMode.OpenOrCreate, FileAccess.Write);
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, mail);
            fs.Close();
        }
Beispiel #6
0
        /// <summary>
        /// 读取本地邮件配置
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Entity.Mail OpenMailSet(string name)
        {
            FileStream      fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config\" + name + ".XML", FileMode.OpenOrCreate, FileAccess.Read);
            BinaryFormatter bf = new BinaryFormatter();

            Entity.Mail mail = (Entity.Mail)bf.Deserialize(fs);
            fs.Close();
            return(mail);
        }
Beispiel #7
0
        /// <summary>
        /// 读取邮件配置
        /// </summary>
        /// <returns></returns>
        private static Entity.Mail LoadMail()
        {
            FileStream      fs = new FileStream(Directory.GetCurrentDirectory() + @"\Config\BackMail.XML", FileMode.OpenOrCreate, FileAccess.Read);
            BinaryFormatter bf = new BinaryFormatter();

            Entity.Mail m = (Entity.Mail)bf.Deserialize(fs);
            fs.Close();
            return(m);
        }
Beispiel #8
0
        /// <summary>
        /// 批量发送邮件方法
        /// </summary>
        public static void SendToPer(Entity.Mail mail, System.Collections.ArrayList urls)
        {
            //加载邮件配置
            LoadSendMailSet();

            for (int i = 0; i < urls.Count; i++)
            {
                //发送邮件
                SendMail(mail, urls[i].ToString().Trim());
            }
        }
Beispiel #9
0
 /// <summary>
 /// 加载配置
 /// </summary>
 private void LoadSet()
 {
     //主设置
     Entity.Mail mail1 = BLL.FileUse.OpenMailSet("MailSet");
     this.txt_smtp1.Text  = mail1.url;
     this.txt_smtpk1.Text = mail1.port.ToString();
     this.txt_id1.Text    = mail1.account;
     this.txt_pass1.Text  = mail1.pass;
     //备用设置
     Entity.Mail mail2 = BLL.FileUse.OpenMailSet("BackMail");
     this.txt_smtp2.Text  = mail2.url;
     this.txt_smtpk2.Text = mail2.port.ToString();
     this.txt_id2.Text    = mail2.account;
     this.txt_pass2.Text  = mail2.pass;
 }
Beispiel #10
0
 private void UpdateMail(Entity.Mail mail)
 {
     var result = context.Query.From("mail").Where("mail.id", mail.id).Update(new { sent = 1 }).PostData();
 }