พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com
ASP, ASP.NET Articles / Sending E-mail with ASP.NET
Administrator
Mon 21 Nov 2005 12:38:31
การส่ง E-mail ด้วย ASP.NET นั้นง่ายมากครับ
เริ่มจากการเรียกใช้งาน Namespace System.Web.Mail

<%@ Import Namespace="System.Web.Mail" %>

ทำการประกาศ MailMessage object
MailMessage msg = new MailMessage();

ระบุ E-mail ปลายทาง
msg.To = "someone@receiver.com";

ระบุ E-mail ผู้ส่ง
msg.From = "someone@sender.com";

ระบุหัวจดหมาย
msg.Subject = "ทดสอบการส่ง E-mail";

ระบุรูปแบบจดหมายว่าเป็น HTML หรือ Text
msg.BodyFormat = MailFormat.Html; หรือ msg.BodyFormat = MailFormat.Text;

ระบุเนื้อหาจดหมาย
msg.Body = "ทดสอบเนื้อความในจดหมาย";

ส่วนถ้าต้องการแนบไฟล์ใน E-mail
msg.Attachments.Add(new MailAttachment("C:\\attachment\\file.txt));

ระบุ SMTP server
SmtpMail.SmtpServer = "localhost";

ทำการส่งจดหมาย
SmtpMail.Send(msg);

ลองส่ง E-mail กันดูนะครับ
Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login