ASP.NET C# 邮件发送一:利用Jmail组件发送邮件
来源:互联网 发布:淘宝收藏店铺图标 编辑:程序博客网 时间:2024/04/28 08:14
最近刚好在整理自己的代码·以便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"; //例如Eric@163.com
jmailobj.FromName = "邮件测试";
jmailobj.AddRecipient(RecieveAddress, "Name", "A"); //收件人地址
//jmailobj.AddRecipientBCC("test@hotmail.com","ok"); //抄送,一般用不到
//jmailobj.AddRecipientBCC("test@sohu.com.cn","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!";
}
}
}
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"; //例如Eric@163.com
jmailobj.FromName = "邮件测试";
jmailobj.AddRecipient(RecieveAddress, "Name", "A"); //收件人地址
//jmailobj.AddRecipientBCC("test@hotmail.com","ok"); //抄送,一般用不到
//jmailobj.AddRecipientBCC("test@sohu.com.cn","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>
<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类发送邮件 会有源码下载
- ASP.NET C# 邮件发送一:利用Jmail组件发送邮件
- ASP.NET邮件发送,jmail组件
- 利用Jmail组件发送邮件
- ASP.NET+C#使用JMail发送邮件
- ASP JMail组件发送邮件
- c#利用jmail发送邮件
- asp.net+jmail发送邮件
- asp.net jmail 发送邮件
- Jmail组件发送邮件
- 利用Jmail发送邮件
- ASP.Net环境下使用Jmail组件发送邮件
- [转贴]ASP.Net环境下使用Jmail组件发送邮件
- ASP.Net环境下使用Jmail组件发送邮件
- ASP.Net环境下使用Jmail组件发送邮件[收藏]
- ASP.Net环境下使用Jmail组件发送邮件
- ASP.Net环境下使用Jmail组件发送邮件
- ASP.Net环境下使用Jmail组件发送邮件[收藏]
- ASP.Net环境下使用Jmail组件发送邮件
- 春节育儿游戏安排
- ffmpeg的精简
- 再次写给我们这些浮躁的程序员(转)
- Intent与PendingIntent的区别
- 将SQL SERVER中查询到的数据导成一个Excel文件
- ASP.NET C# 邮件发送一:利用Jmail组件发送邮件
- 菜单Check标志设定方法。。
- Eclipse--MyEclipse工具使用技巧
- masert上的TABLE中,新建一个linkButton ,事件不能触发
- EasyJWeb 2.0发布
- flash 绘图API:绘制虚线矩形
- 访美观感之结尾篇:试论“理性人”假说
- VS2008手动实现程序初始画面
- VC++ 6.0实用技巧汇总