Пример #1
0
        public bool Push(Dictionary<string, object> parameters, ref TaskMessage q_parameter)
        {
            System.Threading.Thread.Sleep(10);
            return true;
            //Send
            SmtpModel smtp_p = new SmtpModel(parameters);
            MailModel mail = new MailModel(q_parameter);

            // send email
            bool result = emailSender.Send(mail, smtp_p);

            if (mail.SendErrors > 5)
                result = true;
            q_parameter = mail;
            return result;
        }
Пример #2
0
        public bool Send(MailModel model, SmtpModel con)
        {
            MailMessage msg = new MailMessage();
            try// common validation - prevent major configuration errors
            {
                msg.To.Add(new MailAddress(model.To));
                if (model.From != null)
                    msg.From = new MailAddress(model.From, model.FromAlias);
                else msg.From = new MailAddress(loginAddress(con.Login, con.Server));
                msg.Body = model.Body;
                msg.IsBodyHtml = true;
                msg.Subject = model.Subject;
            }
            catch (Exception e)//model error
            {
                model.SendErrors = 5;
                model.LastSError = "please check email model value:" + e.Message;

                logger.Exception(e, "send email - form", "");
                return true;
            }
            //
            try
            {
                if (!Send(msg, con))//configuration smtp error
                {
                    model.SendErrors = 5;
                    model.LastSError = "some configuration error maybe, please check smtp model value";
                    return false;
                }
                else
                {
                    model.SendErrors = 0 - model.SendErrors;
                    return true;
                }
            }
            catch (Exception e)//or network error
            {
                model.SendErrors++;
                model.LastSError = "unexpected: " + e.Message;

                logger.Exception(e, "send email", "");
                return false;
            }
        }
Пример #3
0
        public bool Push(Dictionary <string, object> parameters, ref TaskMessage q_parameter)
        {
            System.Threading.Thread.Sleep(10);
            return(true);

            //Send
            SmtpModel smtp_p = new SmtpModel(parameters);
            MailModel mail   = new MailModel(q_parameter);

            // send email
            bool result = emailSender.Send(mail, smtp_p);

            if (mail.SendErrors > 5)
            {
                result = true;
            }
            q_parameter = mail;
            return(result);
        }
Пример #4
0
        public bool Send(MailMessage message, SmtpModel con)
        {
            if (con.OverrideCertificateSecurity)
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                {
                    if (con.OverrideX509CertificateSerial == certificate.GetSerialNumberString())
                        return true;
                    return false;
                };
            }
            else
            {
                ServicePointManager.ServerCertificateValidationCallback = null;
            }
            SmtpClient SmtpServer = new SmtpClient(con.Server);
            SmtpServer.Port = con.Port;
            SmtpServer.Credentials = new System.Net.NetworkCredential(con.Login, con.Password);
            SmtpServer.EnableSsl = con.UseSSL;

            SmtpServer.Send(message);

            return true;
        }