Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/06/2009, 13:06
ElClaudio
 
Fecha de Ingreso: junio-2009
Mensajes: 1
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Enviar email con c# .net

Hola te envio un trozo de codigo que use para enviar mails con c# y me funciona bien. Fijate
------------------------------------------------------------------------------------------

using System.Net.Mail;
.
.
.

try
{

SmtpClient smtpMail;

//---Verificar servidor smtp y puertos
if (port != string.Empty)
{
smtpMail = new SmtpClient(smptAddress, Int32.Parse(port));
}
else
{
smtpMail = new SmtpClient(smptAddress);
}
//----------------------
MailAddress _from = new MailAddress(from, "TU_ASUNTO");
MailMessage _mensaje = new MailMessage();

_mensaje.Body = cuerpoMensaje;
_mensaje.Subject = Asunto;
_mensaje.From = _from;
foreach (String unDestino in listaMensaje)
{

_mensaje.To.Add(unDestino);
}

//--------------
if (EnableSsl.ToUpper().Equals("TRUE"))
smtpMail.EnableSsl = true;
//else

//------------Verficar Credenciales
if (user == string.Empty || password == string.Empty)
smtpMail.UseDefaultCredentials = true;
else
smtpMail.Credentials = new System.Net.NetworkCredential(user, password);
//-----------------------------------------------------


//Enviar e-mail
smtpMail.Send(_mensaje);

}
catch (Exception err)
{
Console.WriteLine("ERROR AL ENVIAR MAIL: "+err.Message);

}