コード例 #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            GUIValidation.TrimAllData(new object[] {
                this.textSubject,
                this.textSmartHost
            });

            if (!this.CheckValidation())
                return;
            this.Cursor = Cursors.WaitCursor;
            bool bFlag = true;
            try
            {
                FrameworkParams.wait = new WaitingMsg();
                Mime message = CreateMessage();
                if (cmbSendType._getSelectedID() == (Int64)SendType.SmartHost)
                {
                    SmtpClientEx.QuickSendSmartHost(this.textSmartHost.Text, 25, "",message);
                }
                else if (cmbSendType._getSelectedID()== (Int64)SendType.DNS)
                {
                    using (SmtpClientEx smtp = new SmtpClientEx())
                    {
                        smtp.DnsServers = new string[] { this.textSmartHost.Text};
                        IPAddress[] ips = smtp.GetDestinations(this.textSmartHost.Text);
                        SmtpClientEx.QuickSendSmartHost(ips[0].ToString(), 25, "", message);
                    }
                }
            }
            catch (Exception ex)
            {
                HelpMsgBox.ShowErrorMessage("Gửi mail không thành công.\nVui lòng kiểm tra lại thông tin hoặc dữ liệu đang được sử dụng!");
                bFlag = false;
            }
            finally
            {
                if (FrameworkParams.wait != null) {
                    FrameworkParams.wait.Finish();
                }
            }
            this.Cursor = Cursors.Default;
            if (bFlag)
                this.Close();
        }