
Enviar gmail con visual.C#(cuenta de outlook smtp ya lista)
Publicado por Carlos (2 intervenciones) el 10/06/2015 22:44:27
1.- Importar la referencia Outllok

2.- Los imports
3.- Usar este metodo
2.- Los imports
1
2
3
4
5
6
7
8
9
10
11
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Diagnostics;
3.- Usar este metodo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public void SendGmail()
{
try
{
//Mail Message
MailMessage mM = new MailMessage();
//Mail Address
mM.From = new MailAddress("cuenta@gmail.com");
//receiver email id
mM.To.Add("cuenta@gmail.com");
//subject of the email
mM.Subject = "Titulo del mensaje";
//deciding for the attachment ------------------------- Instarlar fix del windows
//mM.Attachments.Add(new Attachment(@"C:\\Users\\Public\\Pictures\\Sample Pictures\\Pingüinos.jpg"));
//add the body of the email
mM.Body = "Body of the email";
mM.IsBodyHtml = true;
//SMTP client
SmtpClient sC = new SmtpClient("smtp.gmail.com");
//port number for Gmail mail
sC.Port = 587;
//credentials to login in to Gmail account
sC.Credentials = new NetworkCredential("cuenta@gmail.com", "password");
//enabled SSL
sC.EnableSsl = true;
//Send an email
sC.Send(mM);
}//end of try block
catch (Exception ex)
{
Console.Write("mensaje: " + ex.Message);
}//end of catch
}//end of Email Method
Valora esta pregunta


0