asp.net C# ·¢ËÍ Óʼþ ºÍ ¸½¼þ ´úÂë
˵µ½·¢ËÍÓʼþ·¢ËÍ£¬ÏÈÌáÒ»ÏÂSMTP(ºÇºÇ£¬¸ßÊÖ¾ÍÌø¹ýÕâÒ»¶Î°É£¡)¡£ SMTPµÄÈ«³ÆÊÇ“Simple Mail Transfer Protocol”£¬¼´¼òµ¥Óʼþ´«ÊäÐÒé¡£ËüÊÇÒ»×éÓÃÓÚ´ÓÔ´µØÖ·µ½Ä¿µÄµØÖ·´«ÊäÓʼþµÄ¹æ·¶£¬Í¨¹ýËüÀ´¿ØÖÆÓʼþµÄÖÐת·½Ê½¡£SMTP ÐÒéÊôÓÚ TCP/IP ÐÒé´Ø£¬Ëü°ïÖúÿ̨¼ÆËã»úÔÚ·¢ËÍ»òÖÐתÐżþʱÕÒµ½ÏÂÒ»¸öÄ¿µÄµØ¡£SMTP ·þÎñÆ÷¾ÍÊÇ×ñÑ SMTP ÐÒéµÄ·¢ËÍÓʼþ·þÎñÆ÷¡£
ÔÙ¼òµ¥½éÉÜÒ»ÏÂÃû³Æ¿Õ¼ä£¨NameSpace£©System.Web.MailÀà¿âÀïËùÌṩµÄÓʼþ·¢Ë͵ĶÔÏó¡¢ÊôÐԺͷ½·¨
(1)ËüÓÐÈý¸öÀࣺSmtpMail¡¢MailMessageºÍMailAttachment¡£ÕâÈý¸ö¶ÔÏó±¾ÎĵÄʾÀý³ÌÐò´úÂëÖж¼Ó¦Óõ½ÁË£¡
1. MailMessage ,ÌṩÊôÐԺͷ½·¨À´´´½¨Ò»¸öÓʼþÏûÏ¢¶ÔÏó¡£(Provides properties and methods for constructing an e-mail message.)
2. MailAttachments – ÌṩÊôÐԺͷ½·¨À´´´½¨Ò»¸öÓʼþ¸½¼þ¶ÔÏó¡£(Provides properties and methods for constructing an e-mail attachment.)
3. SmtpMail – ÌṩÊôÐԺͷ½·¨Í¨¹ýʹÓÃwindows 2000 CDOSYS µÄÏûÏ¢×é¼þµÄÁªºÏÊý¾Ý¶ÔÏóÀ´·¢ËÍÓʼþÏûÏ¢£©¡£(Provides properties and methods for sending messages using the Collaboration Data Objects for Windows 2000 (CDOSYS) message component)
(2)¸÷¸öÀàµÄÊôÐÔ¡£
1.Ïȼòµ¥½éÉÜSmtpMailµÄÊôÐÔ£º SmtpServer -- SMTPµÄµØÖ·¡£
2.Ö÷ÒªÀ´½éÉÜMailMessage¶ÔÏóµÄÊôÐÔ
from -- ·¢ËÍÓʼþµÄµØÖ·
To -- ½ÓÊÜÓʼþµÄµØÖ·
Subject -- ÓʼþµÄ±êÌâ
Priority -- ÓʼþµÄÓÅÏȼ¶£¨ÓÐЧֵΪHigh,Low,Normal£©
Attachments -- ·µ»ØÒ»¸ö¼¯ºÏ£¬´ú±í¸½¼þ
Bcc -- ÃÜË͵
Ïà¹ØÎĵµ£º
Ê×Ò³£º
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head ......
ÔÚ×î½üµÄÓÃasp.net ¿ª·¢µÄÏîÄ¿ÖУ¬×öÓÅ»¯£¬Òª°ÑÒ³Ã澲̬»¯£¬²éÁ˺ܶàÖÖ·½·¨£¬×îºóÑ¡ÔñÁËÓÃÄ£°åÀ´ÊµÏÖ£¬
×îÖÕÒ³µÄʵÏֱȽϼòµ¥£¬ÔÚÍøÉÏÕÒÁËÒ»¶Î´úÂ룬µ«Ê×Ò³£¬¶þ¼¶Ò³£¬ÁбíÒ³µÄ´¦Àí±¾ÈËÊÇÓõÄÒÔÏ·½°¸£¬ÏÖÔÚ»¹Ö»ÊÇÒ»¸ö±È½Ï¼òµ¥µÄ£¬Ï£ÍûÓдó¼Ò¶à¶àÖ¸µã£¬½»Á÷£»
·½·¨ÈçÏ£º
˼·ÃèÊö£º
1£ ......
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace W ......
ÔÚASP.NETÍøÕ¾¿ª·¢ÖпÉÄÜ»áÓöµ½Òª¸ü»»Êý¾Ý¿â£¬È罫Aceess»»ÎªSQL Server £¬ÓÉÓÚAceessÒýÓÃSystem.Data.OleDbÃüÃû¿Õ¼ä£¬SQL ServerÒýÓÃSystem.Data.SqlClientÃüÃû¿Õ¼ä¡£ÔÚÒ»°ã³ÌÐò´úÂëÖÐÎÒÃÇÐèÒª¸ü¸ÄÁ¬½Ó×Ö·û´®£¬ADO.NETÊý¾Ý·ÃÎÊÃüÁî¶ÔÏó£¬×îÂé·³µÄÊDz»Í¬Êý¾Ý¿âÓи÷×Ô²»Í¬SqlÃüÁî¡£ÎÒÃÇ¿ÉÒÔʹÓóéÏ󹤳§Ä£Ê½ÊµÏÖASP.NET·ÃÎʲ ......
ASP.NET ÅäÖýڼܹ¹°üº¬¿ØÖÆ ASP.NET Web Ó¦ÓóÌÐòÐÐΪµÄÔªËØ¡£Èç¹ûΪÊôÐÔÖ¸¶¨ÁËĬÈÏÖµ£¬Ôò¸ÃĬÈÏÖµÊÇÔÚ Machine.config ÎļþÖÐÉèÖõģ¬¸ÃÎļþµÄ·¾¶ÊÇ systemroot\Microsoft.NET\Framework\versionNumber\CONFIG\Machine.config¡£
<configuration>
<location>
......