您的位置:首页 > 编程语言 > ASP

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>
直接粘过去就能用~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息