Pertama-tama tambahkan import library berikut di bagian paling atas dari source code Form :
using System.Net.Mail;
Kemudian tambahkan kode program berikut untuk mengirimkan email, bisa email teks, HTML atau disertai Attachment berupa Gambar, Dokumen ataupun ZIP.
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("andi@gmail.com");
mail.To.Add("dewi@dewi.com");
mail.Subject = "Halo Boss";
mail.Body = "Halo Boss, Salam Super";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("C:\dokumen.doc");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("andi", "123");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("Email Terkirim");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Ganti email dengan email GMail anda, username dan passwordnya. Dan tambahkan Attachment yang anda inginkan.
salam kanal...
BalasHapuskalau dalam bahasa c ada gak mas.,?
Wah gkada, maaf, terlalu sulit memakai bahasa C..
BalasHapus