Thread: C# основной форум/Sending mail using SmtpClient

Sending mail using SmtpClient

olondono.blogspot.com/2008/02/sending-mail-using-smtpclient.html


// Mail message construction

MailMessage mm = new MailMessage("youraccount@gmail.com", "destination@mail.com");

// content
mm.Subject = "testing message";
mm.Body = "hello... from .net c# mailmessage";
mm.CC.Add("copycc@mail.com");
mm.CC.Add("copycc2@mail.com");
mm.Bcc.Add("copybcc@mail.com");

// some attachments
mm.Attachments.Add(new Attachment("c:\\filename.txt"));

// Sending message
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);

// our account credentials
sc.Credentials = new NetworkCredential("youraccount@gmail.com", "yourpassword", "");
sc.EnableSsl = true;

// Catching result
try
{
    sc.Send(mm);
    MessageBox.Show("Message sent");
}
catch (Exception ex)
{
    MessageBox.Show("Error: " + ex.Message);
}