Exemplo n.º 1
0
        public void SendMail()
        {
            T_MailConfigBLL bllMailCon   = new T_MailConfigBLL();
            T_MailConfig    modelMailCon = bllMailCon.Get();

            if (modelMailCon.ISSHOW)
            {
                this.Show();
            }
            T_MailAddressBLL      bllAdd    = new T_MailAddressBLL();
            IList <T_MailAddress> modelsAdd = bllAdd.GetAll();

            MailMessage mail = new MailMessage();

            mail.From = new MailAddress(modelMailCon.SENDMAIL, modelMailCon.SENDER);
            string title = modelMailCon.MAILTITLE.Replace("[name]", modelIn.name);

            title        = title.Replace("[ip]", modelIn.ip);
            title        = title.Replace("[state]", modelIn.state);
            title        = title.Replace("[reTime]", modelIn.reTime == -1 ? "无" : modelIn.reTime.ToString());
            mail.Subject = title;
            string body = modelMailCon.MAILBODY.Replace("[name]", modelIn.name);

            body      = body.Replace("[ip]", modelIn.ip);
            body      = body.Replace("[state]", modelIn.state);
            body      = body.Replace("[reTime]", modelIn.reTime == -1 ? "无" : modelIn.reTime.ToString());
            mail.Body = body;
            foreach (T_MailAddress modelTemp in modelsAdd)
            {
                mail.To.Add(modelTemp.MAILADDRESS);
            }
            smtp = new SmtpClient();
            smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);
            smtp.Host           = modelMailCon.SENDSMTP;
            smtp.Port           = modelMailCon.SENDPORT;
            smtp.Credentials    = new System.Net.NetworkCredential(modelMailCon.SENDUSER, modelMailCon.SENDPWD);
            smtp.SendAsync(mail, null);
        }
Exemplo n.º 2
0
        private void formMailConfig_Load(object sender, EventArgs e)
        {
            bllCon   = new T_MailConfigBLL();
            modelCon = bllCon.Get();

            chkShow.Checked  = modelCon.ISSHOW;
            txtSendMail.Text = modelCon.SENDMAIL;
            txtSender.Text   = modelCon.SENDER;
            txtSendSMTP.Text = modelCon.SENDSMTP;
            txtSendPort.Text = modelCon.SENDPORT.ToString();
            txtUser.Text     = modelCon.SENDUSER;
            txtPwd.Text      = modelCon.SENDPWD;

            txtTitle.Text = modelCon.MAILTITLE;
            txtBody.Text  = modelCon.MAILBODY;

            bllAdd = new T_MailAddressBLL();
            foreach (T_MailAddress modelTemp in bllAdd.GetAll())
            {
                lstAddress.Items.Add(modelTemp);
                lstAddress.DisplayMember = "MAILADDRESS";
                lstAddress.ValueMember   = "ID";
            }
        }