コード例 #1
0
        private void Initialize()
        {
            // TODO: Move this line to design.cs
            fileMain.FileOk  += new CancelEventHandler(fileMain_FileOk);
            sfdExport.FileOk += new CancelEventHandler(sfdExport_FileOk);
            sfdExport.Filter  = "Eml (*.eml)|*.eml|All File (*.*)|*.*";
            ofdImport.FileOk += new CancelEventHandler(ofdImport_FileOk);
            ofdImport.Filter  = "Eml (*.eml)|*.eml|All File (*.*)|*.*";

            ExpandRecPanel(false);

            // TODO: Change to property
            ScrollLog(true);

            // Initialize for command mode
            cmdSMTPCommunicator = new SMTPCommunicator();
            m_authLogin         = new AuthenticationLogin();
            cmdMgr = new SMTP.Commands.CommandManager();
            cmdMgr.UpdateMessage += new SMTP.Commands.CommandEvent.CommandEventHandler(OnCommandManagerUpdateMessage);
            cmdMgr.Attach(Commands.PackageCommands.Pack(this.cmdSMTPCommunicator));
            cmdMgr.Attach(new Commands.CmdHelp(cmdMgr));

            // Set accept key word command textbox
            acceptKeyHelper = new SMTP.Utility.TextboxAcceptKeyHelper(this.txtCommand);
            acceptKeyHelper.AcceptButton = this.btnCommand;

            // Initialize hex editor
            this.messageBodyBytes = new byte[0];
            textByteProvider      = new Be.Windows.Forms.DynamicByteProvider(this.messageBodyBytes);

            this.hexMessage.ByteProvider = textByteProvider;

            this.CustomizeMessageBody = false;
        }
コード例 #2
0
ファイル: SMTPCommunicator.cs プロジェクト: normanzb/mailtro
 public void MessageBodyUnserialization(SMTPCommunicator _ismtpcommunicator)
 {
 }
コード例 #3
0
ファイル: FormMailtro.cs プロジェクト: normanzb/mailtro
        void sfdExport_FileOk(object sender, CancelEventArgs e)
        {
            FileStream fs = new FileStream(sfdExport.FileName, FileMode.Create);

            if (this.CustomizeMessageBody == true)
            {
                byte[] emlBodyBytes = new byte[hexMessage.ByteProvider.Length];
                for (int i = 0; i < hexMessage.ByteProvider.Length; i++)
                {
                    emlBodyBytes[i] = hexMessage.ByteProvider.ReadByte(i);
                }
                fs.Write(emlBodyBytes,0,emlBodyBytes.Length);
                fs.Close();

            }
            else
            {
                fs.Close();

                //-------------
                // TODO: A new function to bind data from current form to SMTPCommunicator object
                //-------------
                SMTPCommunicator iSMTPC = new SMTPCommunicator();
                iSMTPC.To = this.txtTo.Text;
                iSMTPC.From = this.txtTo.Text;
                //Check whether to send bcc and cc
                if (receiverPanExpand)
                {
                    if (this.txtCc.Text.Trim() != "")
                        iSMTPC.Cc = this.txtCc.Text.Trim();

                    if (this.lblBcc.Text.Trim() != "")
                        iSMTPC.Bcc = this.txtBcc.Text.Trim();

                }
                iSMTPC.Subject = this.txtSubject.Text;

                iSMTPC.Message = this.txtMessage.Text;

                int i;
                if (txtAttachment.Items.Count > 0)
                {

                    //Clear attachment first
                    iSMTPC.Attachments.Clear();
                    for (i = 0; i < this.txtAttachment.Items.Count; i++)
                    {
                        iSMTPC.Attachments.Add((SMTPCommunicator.Attachment)this.txtAttachment.Items[i].Path);
                    }
                }

                // Encoding
                string sMailEncodingName = this.cmbEncodingName.Text;
                if (sMailEncodingName.ToLower() == "default")
                {
                    sMailEncodingName = Encoding.Default.HeaderName;
                }
                iSMTPC.EncodingName = sMailEncodingName;

                iSMTPC.MessageBodySerialization(new SMTPCommunicator.delWriteData(this.ExportWriter));
            }
        }
コード例 #4
0
ファイル: FormMailtro.cs プロジェクト: normanzb/mailtro
        private void SendMailProcess(Utility.ThreadHelper.ThreadHelper.StandardParameters sParams)
        {
            int i;
            int count;
            int sleep;

            count = (int)Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this, "Count");
            sleep = (int)Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this, "Interval");

            //-------------
            // TODO: Change all read property method via delGetProperty
            //-------------

            sc = new SMTPCommunicator();
            sc.OnLogWrite += new MessageEventHandler(this.WriteLog); ;

            //If required authentication, add property.
            if (chkAuthentication.Checked == true)
            {
                sc.Authentication = this.m_authLogin;
            }
            if (chkTls.Checked == true) {
                sc.UseTls = true;
            }
            if (chkBase64.Checked == true) {
                sc.MessageEncoding = MessageEncoding.Base64;
            }
            if (chkMultiPart.Checked == true) {
                sc.EnforceMultiPart = true;
            }
            sc.IPAddress = this.txtSmtpServer.Text;
            sc.Port = Int32.Parse(this.txtPort.Text);
            sc.From = this.txtFrom.Text;
            sc.To = this.txtTo.Text;

            string sMailEncodingName = SMTP.Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this.cmbEncodingName, "Text").ToString();
            if (sMailEncodingName.ToLower() == "default")
            {
                sMailEncodingName = Encoding.Default.HeaderName;
            }
            sc.EncodingName = sMailEncodingName;

            //Check whether to send bcc and cc
            if (receiverPanExpand)
            {
                if (this.txtCc.Text.Trim() != "")
                    sc.Cc = this.txtCc.Text.Trim();

                if (this.lblBcc.Text.Trim() != "")
                    sc.Bcc = this.txtBcc.Text.Trim();

            }

            sc.Subject = this.txtSubject.Text;
            sc.CustomizeMessageBody = (bool)Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this, "CustomizeMessageBody");
            if (sc.CustomizeMessageBody == true)
                sc.Message = Encoding.Default.GetString(this.textByteProvider.Bytes.ToArray());
            else
                sc.Message = this.txtMessage.Text;

            if (txtAttachment.Items.Count > 0)
            {

                //Clear attachment first
                sc.Attachments.Clear();
                for (i = 0; i < this.txtAttachment.Items.Count; i++)
                {
                    sc.Attachments.Add((SMTPCommunicator.Attachment)this.txtAttachment.Items[i].Path);
                }
            }

            for (i = 0; i < count; i++)
            {
                //If StopSending property is set to true, stop send mail.
                if (threadSendMail.CancelSignal.Get())
                {
                    break;
                }

                try
                {
                    sc.Open();
                    sc.Send();
                }
                catch (Exception ex)
                {
                    // if the canceling signal is not set,
                    // then it must be a unexpected exception.
                    if (!threadSendMail.CancelSignal.Get())
                    {
                        // TODO: add ability to log list to view all text in it.
                        this.WriteLogToitemlist(ex.Message);
                    }
                }
                finally
                {
                    //Utility.ThreadHelper.CrossThreadPropertyHelper.SetProperty(this, "Progress", (int)(i * 100 / count));
                    sc.Close();
                }

                //If current circle is the last one, do not sleep.
                if (i + 1 < count)
                {
                    Thread.CurrentThread.Join(sleep);
                }
            }
            OnSendCompleted();
        }
コード例 #5
0
ファイル: FormMailtro.cs プロジェクト: normanzb/mailtro
        private void Initialize()
        {
            // TODO: Move this line to design.cs
            fileMain.FileOk += new CancelEventHandler(fileMain_FileOk);
            sfdExport.FileOk += new CancelEventHandler(sfdExport_FileOk);
            sfdExport.Filter = "Eml (*.eml)|*.eml|All File (*.*)|*.*";
            ofdImport.FileOk += new CancelEventHandler(ofdImport_FileOk);
            ofdImport.Filter = "Eml (*.eml)|*.eml|All File (*.*)|*.*";

            ExpandRecPanel(false);

            // TODO: Change to property
            ScrollLog(true);

            // Initialize for command mode
            cmdSMTPCommunicator = new SMTPCommunicator();
            m_authLogin = new AuthenticationLogin();
            cmdMgr = new SMTP.Commands.CommandManager();
            cmdMgr.UpdateMessage += new SMTP.Commands.CommandEvent.CommandEventHandler(OnCommandManagerUpdateMessage);
            cmdMgr.Attach(Commands.PackageCommands.Pack(this.cmdSMTPCommunicator));
            cmdMgr.Attach(new Commands.CmdHelp(cmdMgr));

            // Set accept key word command textbox
            acceptKeyHelper = new SMTP.Utility.TextboxAcceptKeyHelper(this.txtCommand);
            acceptKeyHelper.AcceptButton = this.btnCommand;

            // Initialize hex editor
            this.messageBodyBytes = new byte[0];
            textByteProvider = new Be.Windows.Forms.DynamicByteProvider(this.messageBodyBytes);

            this.hexMessage.ByteProvider = textByteProvider;

            this.CustomizeMessageBody = false;
        }
コード例 #6
0
        private void SendMailProcess(Utility.ThreadHelper.ThreadHelper.StandardParameters sParams)
        {
            int i;
            int count;
            int sleep;

            count = (int)Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this, "Count");
            sleep = (int)Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this, "Interval");

            //-------------
            // TODO: Change all read property method via delGetProperty
            //-------------

            sc             = new SMTPCommunicator();
            sc.OnLogWrite += new MessageEventHandler(this.WriteLog);;

            //If required authentication, add property.
            if (chkAuthentication.Checked == true)
            {
                sc.Authentication = this.m_authLogin;
            }
            if (chkTls.Checked == true)
            {
                sc.UseTls = true;
            }
            if (chkBase64.Checked == true)
            {
                sc.MessageEncoding = MessageEncoding.Base64;
            }
            if (chkMultiPart.Checked == true)
            {
                sc.EnforceMultiPart = true;
            }
            sc.IPAddress = this.txtSmtpServer.Text;
            sc.Port      = Int32.Parse(this.txtPort.Text);
            sc.From      = this.txtFrom.Text;
            sc.To        = this.txtTo.Text;

            string sMailEncodingName = SMTP.Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this.cmbEncodingName, "Text").ToString();

            if (sMailEncodingName.ToLower() == "default")
            {
                sMailEncodingName = Encoding.Default.HeaderName;
            }
            sc.EncodingName = sMailEncodingName;

            //Check whether to send bcc and cc
            if (receiverPanExpand)
            {
                if (this.txtCc.Text.Trim() != "")
                {
                    sc.Cc = this.txtCc.Text.Trim();
                }

                if (this.lblBcc.Text.Trim() != "")
                {
                    sc.Bcc = this.txtBcc.Text.Trim();
                }
            }

            sc.Subject = this.txtSubject.Text;
            sc.CustomizeMessageBody = (bool)Utility.ThreadHelper.CrossThreadPropertyHelper.GetProperty(this, "CustomizeMessageBody");
            if (sc.CustomizeMessageBody == true)
            {
                sc.Message = Encoding.Default.GetString(this.textByteProvider.Bytes.ToArray());
            }
            else
            {
                sc.Message = this.txtMessage.Text;
            }


            if (txtAttachment.Items.Count > 0)
            {
                //Clear attachment first
                sc.Attachments.Clear();
                for (i = 0; i < this.txtAttachment.Items.Count; i++)
                {
                    sc.Attachments.Add((SMTPCommunicator.Attachment) this.txtAttachment.Items[i].Path);
                }
            }

            for (i = 0; i < count; i++)
            {
                //If StopSending property is set to true, stop send mail.
                if (threadSendMail.CancelSignal.Get())
                {
                    break;
                }

                try
                {
                    sc.Open();
                    sc.Send();
                }
                catch (Exception ex)
                {
                    // if the canceling signal is not set,
                    // then it must be a unexpected exception.
                    if (!threadSendMail.CancelSignal.Get())
                    {
                        // TODO: add ability to log list to view all text in it.
                        this.WriteLogToitemlist(ex.Message);
                    }
                }
                finally
                {
                    //Utility.ThreadHelper.CrossThreadPropertyHelper.SetProperty(this, "Progress", (int)(i * 100 / count));
                    sc.Close();
                }

                //If current circle is the last one, do not sleep.
                if (i + 1 < count)
                {
                    Thread.CurrentThread.Join(sleep);
                }
            }
            OnSendCompleted();
        }
コード例 #7
0
        void sfdExport_FileOk(object sender, CancelEventArgs e)
        {
            FileStream fs = new FileStream(sfdExport.FileName, FileMode.Create);

            if (this.CustomizeMessageBody == true)
            {
                byte[] emlBodyBytes = new byte[hexMessage.ByteProvider.Length];
                for (int i = 0; i < hexMessage.ByteProvider.Length; i++)
                {
                    emlBodyBytes[i] = hexMessage.ByteProvider.ReadByte(i);
                }
                fs.Write(emlBodyBytes, 0, emlBodyBytes.Length);
                fs.Close();
            }
            else
            {
                fs.Close();

                //-------------
                // TODO: A new function to bind data from current form to SMTPCommunicator object
                //-------------
                SMTPCommunicator iSMTPC = new SMTPCommunicator();
                iSMTPC.To   = this.txtTo.Text;
                iSMTPC.From = this.txtTo.Text;
                //Check whether to send bcc and cc
                if (receiverPanExpand)
                {
                    if (this.txtCc.Text.Trim() != "")
                    {
                        iSMTPC.Cc = this.txtCc.Text.Trim();
                    }

                    if (this.lblBcc.Text.Trim() != "")
                    {
                        iSMTPC.Bcc = this.txtBcc.Text.Trim();
                    }
                }
                iSMTPC.Subject = this.txtSubject.Text;

                iSMTPC.Message = this.txtMessage.Text;

                int i;
                if (txtAttachment.Items.Count > 0)
                {
                    //Clear attachment first
                    iSMTPC.Attachments.Clear();
                    for (i = 0; i < this.txtAttachment.Items.Count; i++)
                    {
                        iSMTPC.Attachments.Add((SMTPCommunicator.Attachment) this.txtAttachment.Items[i].Path);
                    }
                }

                // Encoding
                string sMailEncodingName = this.cmbEncodingName.Text;
                if (sMailEncodingName.ToLower() == "default")
                {
                    sMailEncodingName = Encoding.Default.HeaderName;
                }
                iSMTPC.EncodingName = sMailEncodingName;

                iSMTPC.MessageBodySerialization(new SMTPCommunicator.delWriteData(this.ExportWriter));
            }
        }
コード例 #8
0
ファイル: SMTPCommunicator.cs プロジェクト: normanzb/mailtro
 public void MessageBodyUnserialization(SMTPCommunicator _ismtpcommunicator)
 {
 }