You are on page 1of 2

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net.Mime;

namespace EnviarCorreo
{
public partial class Form1 : Form
{

private string To;


private string Subject;
private string Body;

private MailMessage mail;


private Attachment Data;

public Form1()
{
InitializeComponent();
}

private void examinarBtn_Click(object sender, EventArgs e)


{
openFileDialog1.ShowDialog();
archivoAdjTxt.Text = openFileDialog1.FileName;
}

private void enviarBtn_Click(object sender, EventArgs e)


{
if (!(toTxt.Text.Trim() == ""))
{
To = toTxt.Text;
Subject = asuntoTxt.Text;
Body = mensajeTxt.Text;

mail = new MailMessage();


mail.To.Add(new MailAddress(this.To));
mail.From = new MailAddress("tu correo@hotmail.com");
mail.Subject = Subject;
mail.Body = Body;
mail.IsBodyHtml = false;

if (!(archivoAdjTxt.Text.Trim() == ""))
{
Data = new Attachment(archivoAdjTxt.Text,
MediaTypeNames.Application.Octet);
mail.Attachments.Add(Data);
}

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


using (client)
{
client.Credentials = new System.Net.NetworkCredential("tu
correo@hotmail.com", "contrase�a del correo");
client.EnableSsl = true;
client.Send(mail);
}
MessageBox.Show("Mensaje enviado Exitosamente");
}
}

}
}

You might also like