0% found this document useful (0 votes)
20 views

Gui Mail

This document contains code to send an email using the SmtpClient class in .NET. It creates a SmtpClient object and configures it with the Gmail SMTP server settings. It then creates a MailMessage, adds the from, to, subject, and body. It handles any exceptions and sends the email.

Uploaded by

thaitb
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Gui Mail

This document contains code to send an email using the SmtpClient class in .NET. It creates a SmtpClient object and configures it with the Gmail SMTP server settings. It then creates a MailMessage, adds the from, to, subject, and body. It handles any exceptions and sends the email.

Uploaded by

thaitb
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

using System.

Net;
using System.Net.Mail;

SmtpClient SmtpServer = new


SmtpClient();
SmtpServer.Credentials = new
System.Net.NetworkCredential("ca
[email protected]",
"qlktktk21");
SmtpServer.Port = 587;
SmtpServer.Host =
"smtp.gmail.com";
SmtpServer.EnableSsl =
true;
MailMessage mail = new
MailMessage();
String[] addr =
txtTo.Text.Split(',');
try
{
mail.From = new
MailAddress("[email protected]
", "thai Gui Mail",
System.Text.Encoding.UTF8);
Byte i;
for (i = 0; i <
addr.Length; i++)
mail.To.Add(]);
mail.Subject =
txtSubject.Text;
mail.Body =
txtConTent.Text;
//if
(lbAttachFile.Items.Count != 0)
//{
// for (i = 0; i
< lbAttachFile.Items.Count; i++)
mail.Attachments.Add(new
Attachment("DETHI_LT_WIN.doc"));
//}
mail.DeliveryNotificationOptions
=
DeliveryNotificationOptions.OnFa
ilure;
mail.ReplyTo = new
MailAddress(txtTo.Text);

SmtpServer.Send(mail);
}
catch (Exception ex) {

Response.Write(ex.ToString());
}
}

MailMessage message = new


MailMessage();
message.From = new
MailAddress("kimloan070382@yahoo
.com.vn","thai
gui",System.Text.Encoding.UTF8);
// message.From = new
MailAddress("kimloan070382@yahoo
.com.vn");
message.To.Add(new
MailAddress("truongbathai@yahoo.
com"));
//message.To.Add(new
MailAddress("[email protected].
com"));
//message.To.Add(new
MailAddress("[email protected].
com"));

//message.CC.Add(new
MailAddress("[email protected].
com"));
message.Subject =
"This is my subject";
message.Body =
"Tthai gui ";
SmtpClient client =
new
SmtpClient("smtp.mail.yahoo.com"
, 25);
// SmtpClient client
= new SmtpClient();
client.Credentials =
new
NetworkCredential("kimloan070382
", "07031982");
// SmtpClient client
= new SmtpClient();

client.Send(message);

}
catch (Exception ex)
{
Response.Write("Không gởi được!"
+ ex.ToString());
}

You might also like