Exemplo n.º 1
0
 public bool GmailSender(string From, string To, string Subject, string Body, bool IsBodyHTML)
 {
     try
     {
         MailMessage mail = new MailMessage();
         mail.From = new MailAddress(From);
         mail.To.Add(To);
         mail.Subject    = Subject;
         mail.Body       = Body;
         mail.IsBodyHtml = IsBodyHTML;
         SmtpClient smtp = new SmtpClient(From, 587);
         smtp.UseDefaultCredentials = false;
         smtp.EnableSsl             = true;
         smtp.Credentials           = new NetworkCredential(UserName, Password);
         //smtp.Credentials = new NetworkCredential("*****@*****.**", "m8211106756");
         smtp.Timeout = 3000;
         smtp.Send(mail);
         smtp.Dispose();
         return(true);
     }
     catch (Exception Ex)
     {
         EmailBankCore.LogRegister("GmailSender", Ex.Message);
         //System.Diagnostics.EventLog.WriteEntry(To, Ex.ToString());
         return(false);
     }
 }
Exemplo n.º 2
0
        public bool EmailSender(string From, string To, string Subject, string Body, bool IsBodyHTML, int RepeatCount, ref string ErrorMessage)
        {
            int          c        = RepeatCount + 1;
            SMTPProperty smtpprop = new SMTPProperty();

            try
            {
                if (RepeatCount <= 3)
                {
                    smtpprop = GetActiveSmtpClient();
                    MailMessage mail = new MailMessage();
                    mail.From = new MailAddress(From);
                    mail.To.Add(To);
                    mail.Subject    = Subject;
                    mail.Body       = Body;
                    mail.IsBodyHtml = IsBodyHTML;
                    smtpprop.ISbusy = true;
                    smtpprop.SMTP.Send(mail);
                    smtpprop.ISbusy = false;
                    ErrorMessage    = "";
                    return(true);

                    //SmtpClient smtp = new SmtpClient(SMTPserverAddress, Port);
                    //smtp.Timeout = 1000000;
                    //smtp.EnableSsl = false;
                    //smtp.UseDefaultCredentials = false;
                    //smtp.Credentials = new NetworkCredential(CridentionalUserName, Password);
                    //MailMessage mail = new MailMessage();
                    //mail.From = new MailAddress(From);
                    //mail.To.Add(To);
                    //mail.Subject = Subject;
                    //mail.Body = Body;
                    //mail.IsBodyHtml = IsBodyHTML;
                    //smtp.Send(mail);
                    //ErrorMessage = "";
                    //smtp.Dispose();
                    //return true;
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception Ex)
            {
                EmailBankCore.LogRegister("EmailSender To : " + To, Ex.Message);
                //smtpprop.ISbusy = false;
                ErrorMessage = Ex.Message;
                System.Threading.Thread.Sleep(1000);
                bool bl = EmailSender(From, To, Subject, Body, IsBodyHTML, c, ref ErrorMessage);
                return(bl);
            }
        }
Exemplo n.º 3
0
 public SmtpClient GetNewSMTP()
 {
     try
     {
         SmtpClient smtp = new SmtpClient(SMTPserverAddress, Port);
         smtp.Timeout               = 1000000;
         smtp.EnableSsl             = false;
         smtp.UseDefaultCredentials = false;
         smtp.Credentials           = new NetworkCredential(CridentionalUserName, Password);
         return(smtp);
     }
     catch (Exception ex)
     {
         EmailBankCore.LogRegister("GetNewSMTP", ex.Message);
         SmtpClient smtp = new SmtpClient(SMTPserverAddress, Port);
         smtp.Timeout               = 1000000;
         smtp.EnableSsl             = false;
         smtp.UseDefaultCredentials = false;
         smtp.Credentials           = new NetworkCredential(CridentionalUserName, Password);
         return(smtp);
     }
 }
Exemplo n.º 4
0
 public SMTPProperty GetActiveSmtpClient()
 {
     try
     {
         if (SMTPList.Count <= 0)
         {
             SmtpClient   smtp  = GetNewSMTP();
             SMTPProperty smtpp = new SMTPProperty {
                 SMTP = smtp, ISbusy = false, TTL = Environment.TickCount
             };
             SMTPList.Add(smtpp);
             return(SMTPList[SMTPList.Count - 1]);
         }
         else
         {
             int i = 0;
             while (SMTPList[i].ISbusy)
             {
                 i++;
                 if (i >= SMTPList.Count)
                 {
                     if (i <= 50)
                     {
                         SmtpClient   smtp  = GetNewSMTP();
                         SMTPProperty smtpp = new SMTPProperty {
                             SMTP = smtp, ISbusy = false, TTL = Environment.TickCount
                         };
                         SMTPList.Add(smtpp);
                         return(SMTPList[SMTPList.Count - 1]);
                     }
                     else
                     {
                         System.Threading.Thread.Sleep(1000);
                         return(GetActiveSmtpClient());
                     }
                 }
             }
             long Tick = Environment.TickCount;
             if ((-SMTPList[i].TTL) > 1000000)
             {
                 SmtpClient   smtp  = GetNewSMTP();
                 SMTPProperty smtpp = new SMTPProperty {
                     SMTP = smtp, ISbusy = false, TTL = Environment.TickCount
                 };
                 SMTPList[i] = smtpp;
             }
             return(SMTPList[i]);
         }
     }
     catch (Exception ex)
     {
         EmailBankCore.LogRegister("GetActiveSmtpClient", ex.Message);
         SmtpClient smtp = new SmtpClient(SMTPserverAddress, Port);
         smtp.UseDefaultCredentials = false;
         smtp.EnableSsl             = false;
         smtp.Credentials           = new NetworkCredential(CridentionalUserName, Password);
         SMTPProperty smtpp = new SMTPProperty {
             SMTP = smtp, ISbusy = false, TTL = Environment.TickCount
         };
         return(smtpp);
     }
 }