Skip to content

Instantly share code, notes, and snippets.

@davidcrx
Created March 15, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcrx/e9d1a5923fd5d65c931666834843d355 to your computer and use it in GitHub Desktop.
Save davidcrx/e9d1a5923fd5d65c931666834843d355 to your computer and use it in GitHub Desktop.
Enviar correo con fichero adjunto
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net.Mime;
namespace send_mail
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEnviarMail_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com");
mail.From = new MailAddress("your_username@...com");
mail.To.Add("your_username@...com");
mail.Subject = "Prueba de correo";
mail.Body = "Correo con mensaje adjunto!";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:/test.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("your_username", "your_password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
}
}
@lpalominovargas321
Copy link

Gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment