Exemple #1
0
        private void SendRemindMail()
        {
            try
            {
                //load smtp config info
                SmtpInfo smtpInfo = ConfigCtrl.GetSmtp();
                if (smtpInfo == null)
                {
                    SetMessageLn("Smtp配置信息读取失败,无法发送日志!");
                    return;
                }

                MailHelper.SendMail(smtpInfo.SmtpHost, smtpInfo.SmtpPort, smtpInfo.SenderEmail, smtpInfo.Password, Task.ReceiverEmail, "开心助手运行日志:" + DateTime.Now.ToString(), this.ExecutionLog.ToString());

                SetMessageLn("运行日志已发送到" + Task.ReceiverEmail + "!");
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (ThreadInterruptedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                LogHelper.Write("TaskManager.SendRemindMail", ex, LogSeverity.Error);
                SetMessageLn("发送日志失败!错误:" + ex.Message);
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckData())
                    return;

                SmtpInfo smtp = new SmtpInfo();
                smtp.SmtpHost = txtSmtpHost.Text;
                smtp.SmtpPort = DataConvert.GetInt32(txtSmtpPort.Text);
                smtp.SenderName = txtSenderName.Text;
                smtp.SenderEmail = txtSenderEmail.Text;
                smtp.UserName = txtUserName.Text;
                smtp.Password = txtPassword.Text;

                if (!ConfigCtrl.SetSmtp(smtp))
                {
                    MessageBox.Show("保存失败!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox("DlgSmtpSetting", ex);
            }
        }
Exemple #3
0
        public static bool SetSmtp(SmtpInfo smtp)
        {
            try
            {
                XmlDocument objXmlDoc = GetAssistantConfigFile();
                if (objXmlDoc == null)
                    return false;

                XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.SMTP_SMTP);
                if (objNode == null)
                    return false;

                objNode.SelectSingleNode(Constants.SMTP_HOST).InnerText = smtp.SmtpHost;
                objNode.SelectSingleNode(Constants.SMTP_PORT).InnerText = smtp.SmtpPort.ToString();
                objNode.SelectSingleNode(Constants.SMTP_SENDERNAME).InnerText = smtp.SenderName;
                objNode.SelectSingleNode(Constants.SMTP_SENDEREMAIL).InnerText = smtp.SenderEmail;
                objNode.SelectSingleNode(Constants.SMTP_USERNAME).InnerText = smtp.UserName;
                objNode.SelectSingleNode(Constants.SMTP_PASSWORD).InnerText = smtp.Password;

                return SetAssistantConfigFile(objXmlDoc);

            }
            catch (Exception ex)
            {
                LogHelper.Write("保存SMTP设置", ex);
                return false;
            }
        }
Exemple #4
0
        public static SmtpInfo GetSmtp()
        {
            try
            {
                XmlDocument objXmlDoc = GetAssistantConfigFile();
                if (objXmlDoc == null)
                    return null;

                SmtpInfo smtp = new SmtpInfo();

                XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.SMTP_SMTP);
                if (objNode == null)
                    return null;

                smtp.SmtpHost = DataConvert.GetString(objNode.SelectSingleNode(Constants.SMTP_HOST).InnerText);
                smtp.SmtpPort = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.SMTP_PORT).InnerText);
                smtp.SenderName = DataConvert.GetString(objNode.SelectSingleNode(Constants.SMTP_SENDERNAME).InnerText);
                smtp.SenderEmail = DataConvert.GetString(objNode.SelectSingleNode(Constants.SMTP_SENDEREMAIL).InnerText);
                smtp.UserName = DataConvert.GetString(objNode.SelectSingleNode(Constants.SMTP_USERNAME).InnerText);
                smtp.Password = DataConvert.GetString(objNode.SelectSingleNode(Constants.SMTP_PASSWORD).InnerText);

                return smtp;
            }
            catch (Exception ex)
            {
                LogHelper.Write("读取SMTP设置", ex);
                throw;
            }
        }