using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e) {
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]"); // mail ที่ส่งถึง
mail.From = new MailAddress("[email protected]"); // mail ที่ใช้ส่ง
mail.Subject = "Email using Gmail";
string Body = "Hi, this mail is to test sending mail" +
"using Gmail in ASP.NET";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); // username และ password ของ gmail
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
Response.Write("Message send successfully");
}
}