Created
March 15, 2018 09:39
-
-
Save davidcrx/e9d1a5923fd5d65c931666834843d355 to your computer and use it in GitHub Desktop.
Enviar correo con fichero adjunto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("[email protected]"); | |
mail.To.Add("[email protected]"); | |
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias