Ver Mensaje Individual
  #12 (permalink)  
Antiguo 03/04/2008, 05:18
Avatar de Bravenap
Bravenap
 
Fecha de Ingreso: noviembre-2002
Ubicación: Los Arroyos, El Escorial, Madrid
Mensajes: 2.084
Antigüedad: 24 años
Puntos: 4
Re: Envío de muchos correos en multitarea (C#)

He probado con este código pero ningún candidato recibe los avisos:

Código PHP:
        private void envioMasivo()
        {
            
string message = "<body>" +
                
"<font><b><i>\"" + this.txtNomEmp.Text + "\"</i></b> " +
                
"ofrece el puesto de <b><i>\"" +
                
this.txtPuesto.Text + "\"</i></b><br>. " +
                
"<a href='http://miportaldeempleo.com/Oferta.aspx?id_oferta=" + id_oferta + "'" + 
                
"'>Ver oferta/a></font>" +
                
"</body>";

            
string strCon = ConfigurationSettings.AppSettings["constring"];
            
con = new SqlConnection(strCon);
            
string strSql = "SELECT mail FROM candidatos";
            
SqlCommand cmd = new SqlCommand(strSql,con);
            
SqlDataReader r = cmd.ExecuteReader();

            
DateTime inicio = new DateTime();
            
inicio = DateTime.Now;
            
TimeSpan resta = new TimeSpan();
            
int numEnvios = 0;
            
int numMaxEnvios = 150;
            while(
r.Read())
            {
                
Cartero.Mensaje mail = new Cartero.Mensaje();
                
mail.Hacia = r.GetValue(0).ToString();
                
mail.Titulo = "¡¡Nueva oferta!!";
                
mail.Cuerpo = message;
                    
                try
                {
                    
mail.enviar();
                }
                catch {} 
//No hacemos nada si falla
                
resta = DateTime.Now.Subtract(inicio);
                
numEnvios += 1;                
                
                if(
numEnvios > numMaxEnvios)
                {        
                    while(
resta.Seconds < 60)
                    {
                        
Thread.Sleep(1000);
                        
resta = DateTime.Now.Subtract(inicio);
                    }
                
numEnvios = 0;
                
inicio = DateTime.Now;
                }
            }
            
r.Close();
            
cmd.Dispose();
        } 
¿Veis algún fallo?
__________________
¡¡NO A LA GUERRA!!
Si ponemos a nuestros mensajes títulos adecuados, la gente se animará más a abrirlos y resultarán más útiles en las busquedas. ¡No a los ayuuudaaa, urgenteee y similares!