Está en la página 1de 2

program.

cs:

logic objLogic = new logic();


string body = @"<style>
h1{color:dodgerblue;}
h2{color:darkorange;}
</style>
<h1>Este es el body del correo</h1></br>
<h2>Este es el segundo párrafo</h2>";
objLogic.sendMail("correo.destino@dominio.com", "Este correo fue
enviado via C-sharp",body);

logic.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net;

namespace EnviarMail
{
class logic
{
public string sendMail( string to, string asunto, string body)
{
string msge = "Error al enviar este correo. Por favor verifique los
datos o intente más tarde.";
string from = "correo.origen@dominio.com";
string displayName = "Nombre Para Mostrar";
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from, displayName);
mail.To.Add(to);

mail.Subject = asunto;
mail.Body = body;
mail.IsBodyHtml = true;

SmtpClient client = new SmtpClient("smtp.office365.com", 587);


//Aquí debes sustituir tu servidor SMTP y el puerto
client.Credentials = new NetworkCredential(from,
"ContraseñaDelCorreo");
client.EnableSsl = true;//En caso de que tu servidor de correo no
utilice cifrado SSL,poner en false

client.Send(mail);
msge = "¡Correo enviado exitosamente! Pronto te contactaremos.";

}
catch (Exception ex)
{
msge = ex.Message + ". Por favor verifica tu conexión a internet y
que tus datos sean correctos e intenta nuevamente.";
}

return msge;
}
}
}

También podría gustarte