最近刚好在整理自己的代码·以便review 所以刚好把以前列出来
此文说下用Jmail组件的邮件发送
基于B/S架构的邮件发送,讲下最常用最流行的一种方法,利用jmail 组件,Google搜索下载安装
安装完毕,新建VS2005网站项目,添加引用 浏览
C:/Program Files/Dimac/w3JMail4目录的 jmail.dll 文件夹 确定 (至于如何添加引用 见Baidu)确定
系统会自动创建Bin文件夹 并含有Interop.jmail.dll文件
邮件发送的 MailSender.aspx.cs 代码如下(经测试可以运行,决不发至少在本机不能有BUG的源码)
代码都有详细的注释

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;


using jmail; // 引用


public partial class System_MailSender : System.Web.UI.Page
... {
protected void Page_Load(object sender, EventArgs e)
...{
}
protected void SendBtn_Click(object sender, EventArgs e)
...{
string RecieveAddress = Addresssee.Text; //收件者Email
//string MyAddress = PostMail.Text;
string EmailTheme = theme.Text; //邮件主题
string Content = EmailContent.Text; //邮件内容
//-------------------------------------------------------------------------------------------------
Message jmailobj = new Message();
jmailobj.Logging = true;
jmailobj.Silent = true;
jmailobj.MailServerUserName = "Test"; //发信邮件服务器的帐号 因为我公司的邮件没有设密码
jmailobj.MailServerPassWord = "123"; //密码
//例如 163的邮箱 有户名 为 Test 密码123
jmailobj.Body = Content; //上面定义的EmailContent
jmailobj.Charset = "gb2312";
jmailobj.Subject = EmailTheme;
jmailobj.From = "自个的Email"; //例如[email protected]
jmailobj.FromName = "邮件测试";
jmailobj.AddRecipient(RecieveAddress, "Name", "A"); //收件人地址
//jmailobj.AddRecipientBCC("[email protected]","ok"); //抄送,一般用不到
//jmailobj.AddRecipientBCC("[email protected]","ok");
jmailobj.Priority = 1;
if (jmailobj.Send("shex01.sh.deltagroup.com", false)) //shex01.sh.deltagroup.com 发送邮件服务器
...{
Label1.Text = "Send to Success";
}
else
...{
Label1.Text = "Send to faild!";
}
}
}

MailSender.aspx Html 代码如下 :

< html xmlns ="http://www.w3.org/1999/xhtml" >

< head runat ="server" >

< title > 无标题页 </ title >

</ head >

< body >

< form id ="form1" runat ="server" >

< div >

< table style ="width: 599px" >

< tr >

< td style ="width: 97px; text-align: right; height: 26px;" >

收件人地址: </ td >

< td style ="width: 108px; height: 26px;" >

< asp:TextBox ID ="Addresssee" runat ="server" Width ="112px" ></ asp:TextBox ></ td >

< td style ="height: 26px" >

</ td >

</ tr >

< tr >

< td style ="width: 97px; text-align: right" >

发件人地址: </ td >

< td style ="width: 108px" >

< asp:TextBox ID ="PostMail" runat ="server" Width ="112px" ></ asp:TextBox ></ td >

< td >

</ td >

</ tr >

< tr >

< td style ="width: 97px; text-align: right" >

主题: </ td >

< td style ="width: 108px" >

< asp:TextBox ID ="theme" runat ="server" Width ="112px" ></ asp:TextBox ></ td >

< td >

</ td >

</ tr >

< tr >

< td style ="width: 97px; height: 124px; text-align: right" >

内容: </ td >

< td colspan ="2" style ="height: 124px" >

< asp:TextBox ID ="EmailContent" runat ="server" Height ="237px" TextMode ="MultiLine" Width ="487px" ></ asp:TextBox ></ td >

</ tr >

< tr >

< td style ="width: 97px; height: 39px; text-align: right" >

</ td >

< td style ="width: 108px; height: 39px" >

< asp:Button ID ="Button1" runat ="server" OnClick ="Button1_Click" Text ="发送邮件" Width ="84px" />


< asp:Label ID ="Label1" runat ="server" Text ="Label" Width ="379px" ></ asp:Label ></ td >

< td style ="height: 39px" >

</ td >

</ tr >

</ table >

< br />

< rsweb:reportviewer id ="ReportViewer1" runat ="server" height ="100px" width ="597px" ></ rsweb:reportviewer >

< br />


</ div >

</ form >

</ body >

</ html >
在ASP.NET C# 邮件发送二:利用C# Mail类发送邮件 会有源码下载