Пример #1
0
        private void btnTestEmail_Click(object sender, EventArgs e)
        {
            Quiksoft.EasyMail.SMTP.License.Key = "Muroc Systems, Inc. (Single Developer)/9983782F406978487783FBAA248A#E86A";
            Quiksoft.EasyMail.SSL.License.Key  = "Muroc Systems, Inc. (Single Developer)/9984652F406991896501FC33B3#02AE4B";

            const string smtpServerHostName = "smtp.socketlabs.com";
            const string smtpUserName       = "******";
            const string smtpPassword       = "******";

            var ssl  = new Quiksoft.EasyMail.SSL.SSL();
            var smtp = new Quiksoft.EasyMail.SMTP.SMTP();


            EmailMessage msg = new EmailMessage();

            msg.Recipients.Add("*****@*****.**", "Kevin Tst Jones", RecipientType.To);
            msg.Subject    = "KEVIN'S TEST EMAIL";
            msg.From.Email = "*****@*****.**";
            msg.From.Name  = "Mr. blah";
            msg.BodyParts.Add(new Quiksoft.EasyMail.SMTP.BodyPart("三菱電機 増田です。", BodyPartFormat.HTML));
            msg.CharsetEncoding = System.Text.Encoding.UTF8;
            //msg.Attachments.Add("c:\\tesxt.png");
            msg.CustomHeaders.Add("X-xsMessageId", "");
            msg.CustomHeaders.Add("X-xsMailingId", "");
            //message.Headers.Add("X-xsMessageId", email.OrganizationID.ToString());
            //message.Headers.Add("X-xsMailingId", email.EmailID.ToString());

            //Set the SMTP server and secure port.
            var smtpServer = new SMTPServer
            {
                Name     = smtpServerHostName,
                Port     = 465, //Secure port
                Account  = smtpUserName,
                Password = smtpPassword,
                AuthMode = SMTPAuthMode.AuthLogin
            };

            smtp.SMTPServers.Add(smtpServer);

            try
            {
                smtp.Connect(ssl.GetInterface());
                //For performance loop here to send multiple message on the same connection.
                smtp.Send(msg);
                //Disconnect when done.
                smtp.Disconnect();
                MessageBox.Show("Message Sent");
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error sending mail\n\n" + ex.Message);
            }
        }
Пример #2
0
        public override void Run()
        {
            Logs.WriteHeader("Starting Run");
            Emails.UnlockThread(LoginUser, (int)_threadPosition);
            _isDebug = Settings.ReadBool("Debug", false);

            Logs.WriteHeader("Debug: " + _isDebug.ToString());

            Quiksoft.EasyMail.SMTP.License.Key = "Muroc Systems, Inc. (Single Developer)/9983782F406978487783FBAA248A#E86A";
            Quiksoft.EasyMail.SSL.License.Key  = "Muroc Systems, Inc. (Single Developer)/9984652F406991896501FC33B3#02AE4B";

            Quiksoft.EasyMail.SSL.SSL ssl = new Quiksoft.EasyMail.SSL.SSL();

            SMTP smtp = new Quiksoft.EasyMail.SMTP.SMTP();

            //Set the SMTP server and secure port.
            int    port       = Settings.ReadInt("SMTP Port");
            string account    = Settings.ReadString("SMTP UserName");
            var    smtpServer = new SMTPServer
            {
                Name     = Settings.ReadString("SMTP Host"),
                Port     = port, //465, //Secure port
                Account  = account,
                Password = Settings.ReadString("SMTP Password"),
                AuthMode = string.IsNullOrWhiteSpace(account) ? SMTPAuthMode.None : SMTPAuthMode.AuthLogin
            };


            smtp.SMTPServers.Add(smtpServer);
            if (port == 465 || port == 587)
            {
                smtp.Connect(ssl.GetInterface());
            }
            else
            {
                smtp.Connect();
            }
            int count = 0;

            try
            {
                while (true)
                {
                    try
                    {
                        if (ServiceThread.ServiceStopped)
                        {
                            Logs.WriteHeader("ServiceThread.ServiceStopped");
                            break;
                        }

                        if (IsStopped)
                        {
                            Logs.WriteHeader("IsStopped");
                            break;
                        }


                        Email email = GetNextEmail(LoginUser.ConnectionString, (int)_threadPosition);
                        if (email == null)
                        {
                            Thread.Sleep(10000);
                            continue;
                        }
                        SendEmail(email, smtp);
                        count++;
                        Logs.WriteEvent("Processing: #" + count.ToString());
                    }
                    catch (Exception ex)
                    {
                        Logs.WriteEvent("Error sending email - Ending Thread");
                        Logs.WriteException(ex);
                        ExceptionLogs.LogException(LoginUser, ex, "Email", "Error sending email");
                        return;
                    }
                }
            }
            finally
            {
                smtp.Disconnect();
                Logs.WriteHeader("Disconnecting");
            }
        }