ASP.NET 自动发邮件
2010-05-07 16:55
197 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace = "System.Web.Mail"%>
<%@ Import Namespace = "System"%>
<%@ Import Namespace = "System.Text"%>
<%@ Import Namespace = "System.IO"%>
<%@ Import Namespace = "System.Net"%>
<%@ Import Namespace = "System.Net.Sockets"%>
<%@ Import Namespace = "System.Collections"%>
<script language="C#" runat="Server">
void Page_Load(object sender,EventArgs e)
{
info.Text = "你好,欢迎使用本邮件发送系统!";
}
void SendMail(object sender,EventArgs e)
{
MailMessage mm = new MailMessage();
//密送地址
mm.Bcc = black_send.Text;
//邮件内容
mm.Body = TextArea1.Value;
//mm.BodyEncoding = System.Text.UTF8Encoding;
//正文格式
mm.BodyFormat = MailFormat.Html;// MailFormat.Text
//抄送地址
mm.Cc = copy_send.Text;
//发送地址
mm.From = address_send.Text;
//优先级
mm.Priority = /*group.SelectedItem.Value;//*/MailPriority.High; //Low Normal
//邮件主题
mm.Subject = subject.Text;
//目的地址
mm.To = address.Text;
//附件
//mm.Attachments.Add(new MailAttachment("c:\\SCANDISK.LOG"));
try
{
SmtpMail.Send(mm);
info.Text = "邮件发送成功!";
}
catch(Exception ex)
{
info.Text = ex.ToString();
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>mail</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="style.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<p>
</p>
<p>
</p>
<form id="Form1" runat="server">
<table cellSpacing="1" cellPadding="3" width="100%" align="center" bgColor="#000000" border="0">
<tr>
<td bgColor="#e7e7e7">收件人姓名:</td>
<td width="26%" bgColor="#e7e7e7"> <asp:textbox id="getname" runat="server" Wrap="false" TextMode="SingleLine" ReadOnly="false" AutoPostBack="false" BorderStyle="groove"></asp:textbox></td>
<td colspan="2" rowspan="8" bgColor="#e7e7e7"><textarea id="TextArea1" cols=55 rows=15 runat=server width="100%" height="100%"/>
</td>
</tr>
<tr>
<td bgColor="#d6d6d6">收件人地址:</td>
<td bgColor="#d6d6d6"><asp:textbox id="address" runat="server" Wrap="false" TextMode="SingleLine" ReadOnly="false" AutoPostBack="false" BorderStyle="groove"></asp:textbox></td>
</tr>
<tr>
<td bgColor="#e7e7e7">回复地址:</td>
<td bgColor="#e7e7e7"><asp:textbox BorderStyle="groove" ID="address_back" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td bgColor="#d6d6d6">发件人姓名:</td>
<td bgColor="#d6d6d6"><asp:textbox BorderStyle="groove" ID="name_send" runat="server" /></td>
</tr>
<tr>
<td bgColor="#e7e7e7">发件人地址:</td>
<td bgColor="#e7e7e7"><asp:textbox BorderStyle="groove" ID="address_send" runat="server" TextMode="SingleLine" Text="emaildemo@963.net"/></td>
</tr>
<tr>
<td bgColor="#d6d6d6">抄送:</td>
<td bgColor="#d6d6d6"><asp:textbox BorderStyle="groove" ID="copy_send" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td bgColor="#e7e7e7">暗送:</td>
<td bgColor="#e7e7e7"><asp:textbox BorderStyle="groove" ID="black_send" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td bgColor="#d6d6d6">邮件主题:</td>
<td bgColor="#d6d6d6"><asp:textbox BorderStyle="groove" ID="subject" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td width="20%" bgColor="#e7e7e7">优先级:</td>
<td bgColor="#e7e7e7"> <asp:dropdownlist ID="group" runat="server">
<asp:listitem>快速</asp:listitem>
<asp:listitem selected>普通</asp:listitem>
<asp:listitem>慢速</asp:listitem>
</asp:dropdownlist></td>
<td width="28%" bgColor="#e7e7e7">邮件格式:</td>
<td width="26%" bgColor="#e7e7e7"> <asp:dropdownlist ID="format" runat="server">
<asp:listitem>文本格式</asp:listitem>
<asp:listitem selected>HTML格式</asp:listitem>
</asp:dropdownlist></td>
</tr><tr>
<td colspan="4" bgColor="#d6d6d6"><asp:label ID="info" runat="server" Text="你好,欢迎使用本邮件发送系统!"></asp:label></td>
</tr>
<tr>
<td colspan="4" bgColor="#d6d6d6"><asp:button BorderStyle="groove" ID="submit" runat="server" Text="提交" ToolTip="如果都填好了,就按这个按钮发送!" OnClick="SendMail"/></td>
<!--td colspan="4" bgColor="#d6d6d6" width="50%"><asp:button id="cancel" runat=server text="sss"/></td-->
</tr>
</table>
<p> </p></form>
</body>
</HTML>
直接粘过去就能用~~
<%@ Import Namespace = "System.Web.Mail"%>
<%@ Import Namespace = "System"%>
<%@ Import Namespace = "System.Text"%>
<%@ Import Namespace = "System.IO"%>
<%@ Import Namespace = "System.Net"%>
<%@ Import Namespace = "System.Net.Sockets"%>
<%@ Import Namespace = "System.Collections"%>
<script language="C#" runat="Server">
void Page_Load(object sender,EventArgs e)
{
info.Text = "你好,欢迎使用本邮件发送系统!";
}
void SendMail(object sender,EventArgs e)
{
MailMessage mm = new MailMessage();
//密送地址
mm.Bcc = black_send.Text;
//邮件内容
mm.Body = TextArea1.Value;
//mm.BodyEncoding = System.Text.UTF8Encoding;
//正文格式
mm.BodyFormat = MailFormat.Html;// MailFormat.Text
//抄送地址
mm.Cc = copy_send.Text;
//发送地址
mm.From = address_send.Text;
//优先级
mm.Priority = /*group.SelectedItem.Value;//*/MailPriority.High; //Low Normal
//邮件主题
mm.Subject = subject.Text;
//目的地址
mm.To = address.Text;
//附件
//mm.Attachments.Add(new MailAttachment("c:\\SCANDISK.LOG"));
try
{
SmtpMail.Send(mm);
info.Text = "邮件发送成功!";
}
catch(Exception ex)
{
info.Text = ex.ToString();
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>mail</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="style.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<p>
</p>
<p>
</p>
<form id="Form1" runat="server">
<table cellSpacing="1" cellPadding="3" width="100%" align="center" bgColor="#000000" border="0">
<tr>
<td bgColor="#e7e7e7">收件人姓名:</td>
<td width="26%" bgColor="#e7e7e7"> <asp:textbox id="getname" runat="server" Wrap="false" TextMode="SingleLine" ReadOnly="false" AutoPostBack="false" BorderStyle="groove"></asp:textbox></td>
<td colspan="2" rowspan="8" bgColor="#e7e7e7"><textarea id="TextArea1" cols=55 rows=15 runat=server width="100%" height="100%"/>
</td>
</tr>
<tr>
<td bgColor="#d6d6d6">收件人地址:</td>
<td bgColor="#d6d6d6"><asp:textbox id="address" runat="server" Wrap="false" TextMode="SingleLine" ReadOnly="false" AutoPostBack="false" BorderStyle="groove"></asp:textbox></td>
</tr>
<tr>
<td bgColor="#e7e7e7">回复地址:</td>
<td bgColor="#e7e7e7"><asp:textbox BorderStyle="groove" ID="address_back" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td bgColor="#d6d6d6">发件人姓名:</td>
<td bgColor="#d6d6d6"><asp:textbox BorderStyle="groove" ID="name_send" runat="server" /></td>
</tr>
<tr>
<td bgColor="#e7e7e7">发件人地址:</td>
<td bgColor="#e7e7e7"><asp:textbox BorderStyle="groove" ID="address_send" runat="server" TextMode="SingleLine" Text="emaildemo@963.net"/></td>
</tr>
<tr>
<td bgColor="#d6d6d6">抄送:</td>
<td bgColor="#d6d6d6"><asp:textbox BorderStyle="groove" ID="copy_send" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td bgColor="#e7e7e7">暗送:</td>
<td bgColor="#e7e7e7"><asp:textbox BorderStyle="groove" ID="black_send" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td bgColor="#d6d6d6">邮件主题:</td>
<td bgColor="#d6d6d6"><asp:textbox BorderStyle="groove" ID="subject" runat="server" TextMode="SingleLine" /></td>
</tr>
<tr>
<td width="20%" bgColor="#e7e7e7">优先级:</td>
<td bgColor="#e7e7e7"> <asp:dropdownlist ID="group" runat="server">
<asp:listitem>快速</asp:listitem>
<asp:listitem selected>普通</asp:listitem>
<asp:listitem>慢速</asp:listitem>
</asp:dropdownlist></td>
<td width="28%" bgColor="#e7e7e7">邮件格式:</td>
<td width="26%" bgColor="#e7e7e7"> <asp:dropdownlist ID="format" runat="server">
<asp:listitem>文本格式</asp:listitem>
<asp:listitem selected>HTML格式</asp:listitem>
</asp:dropdownlist></td>
</tr><tr>
<td colspan="4" bgColor="#d6d6d6"><asp:label ID="info" runat="server" Text="你好,欢迎使用本邮件发送系统!"></asp:label></td>
</tr>
<tr>
<td colspan="4" bgColor="#d6d6d6"><asp:button BorderStyle="groove" ID="submit" runat="server" Text="提交" ToolTip="如果都填好了,就按这个按钮发送!" OnClick="SendMail"/></td>
<!--td colspan="4" bgColor="#d6d6d6" width="50%"><asp:button id="cancel" runat=server text="sss"/></td-->
</tr>
</table>
<p> </p></form>
</body>
</HTML>
直接粘过去就能用~~
相关文章推荐
- Asp.net Web 定时自动发邮件
- ASP.NET 调用2008部署的SMTP服务自动发邮件
- asp.net调用jmail自动发邮件
- [Asp.net] Web 定时自动发邮件
- 自动发邮件代码 asp asp.net jmail
- ASP.NET 自动发邮件
- ASP.NET MVC之表单集合数据自动绑定到对象属性(集合)中
- 在ASP.NET中自动合并小图片并使用CSS Sprite显示出来
- ASP.NET MVC:创建 ModelBinder 自动 Trim 所有字符串
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(7):服务器端和客户端数据类型的自动转换:泛型集合类型
- asp.net下使用jQuery.AutoComplete完成仿淘宝商品搜索自动完成功能(改进了键盘上下选择体验)
- Asp.net MVC Fckeditor的扩展(支持PV3及自动绑定)
- asp.net 多个css文件内容自动放到一个文件中
- 使用MSBuild自动编译发布你的ASP.NET应用程序
- 在ASP.NET中自动给URL地址加上超链接【转】
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载]
- asp.net 自动遍历实体类
- 改写的一个自动生成图片验证码的类asp.net(vb)
- ASP.NET MVC 获得 view 中的HTML并将其中的内容自动转换成繁体中文。