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 34 35 36 37 38 39 40 41 42 43 44 45
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Net.Mail;
namespace TestMailSendSMTP
{
class Program
{
static void Main(string[] args)
{
MailMessage mm = new MailMessage("source@gmail.com", "dest@gmail.com");
// content
mm.Subject = "testing message";
mm.Body = "hello... from .net c# mailmessage";
mm.CC.Add("oucha21@gmail.com");
// Sending message
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
// our account credentials
sc.Credentials = new NetworkCredential("source@gmail.com", "pass", "");
sc.EnableSsl = true;
// Catching result
try
{
sc.Send(mm);
MessageBox.Show("Message sent");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
} |
Partager