我想写一个用一个几个文本框输入用户E-MAIL:
然后提交Email(Email提交)
但是出错了
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
namespace P123
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtSender;
protected System.Web.UI.WebControls.TextBox txtReceiver;
protected System.Web.UI.WebControls.TextBox txtSubject;
protected System.Web.UI.WebControls.TextBox txtBody;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{ }
void OnSend(object sender,EventArgs arg)
{
MailMessage mail=new MailMessage();
mail.From=txtSender.Text;
mail.To=txtReceiver.Text;
mail.Subject=txtSubject.Text;
mail.Body=txtBody.Text;
smtpMail.SmtpServer="localhost";//这里提示“c:\inetpub\wwwroot\P123\WebForm1.aspx.cs(63): 找不到类型或命名空间名称“smtpMail”(是否缺少 using 指令或程序集引用?)”
smtpMail.Send(mail);"//这里提示“c:\inetpub\wwwroot\P123\WebForm1.aspx.cs(63): 找不到类型或命名空间名称“smtpMail”(是否缺少 using 指令或程序集引用?)”
}
}
}
//Html原码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="P123.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<h3>发送邮件</h3>
发送地址<asp:TextBox ID="txtSender" Runat="server" /><br>
接收地址<asp:TextBox ID="txtReceiver" Runat="server" /><br>
邮件主题<asp:TextBox ID="txtSubject" Runat="server" /><br>
邮件内容<br>
<asp:TextBox ID="txtBody" Runat="server" TextMode="MultiLine" Columns="60" Rows="5" />
<asp:Button ID="Button1" Text="发送" Runat="server" OnClick="OnSend" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 240px"></asp:Button>
</form>
</body>
</HTML>
然后提交Email(Email提交)
但是出错了
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
namespace P123
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtSender;
protected System.Web.UI.WebControls.TextBox txtReceiver;
protected System.Web.UI.WebControls.TextBox txtSubject;
protected System.Web.UI.WebControls.TextBox txtBody;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{ }
void OnSend(object sender,EventArgs arg)
{
MailMessage mail=new MailMessage();
mail.From=txtSender.Text;
mail.To=txtReceiver.Text;
mail.Subject=txtSubject.Text;
mail.Body=txtBody.Text;
smtpMail.SmtpServer="localhost";//这里提示“c:\inetpub\wwwroot\P123\WebForm1.aspx.cs(63): 找不到类型或命名空间名称“smtpMail”(是否缺少 using 指令或程序集引用?)”
smtpMail.Send(mail);"//这里提示“c:\inetpub\wwwroot\P123\WebForm1.aspx.cs(63): 找不到类型或命名空间名称“smtpMail”(是否缺少 using 指令或程序集引用?)”
}
}
}
//Html原码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="P123.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<h3>发送邮件</h3>
发送地址<asp:TextBox ID="txtSender" Runat="server" /><br>
接收地址<asp:TextBox ID="txtReceiver" Runat="server" /><br>
邮件主题<asp:TextBox ID="txtSubject" Runat="server" /><br>
邮件内容<br>
<asp:TextBox ID="txtBody" Runat="server" TextMode="MultiLine" Columns="60" Rows="5" />
<asp:Button ID="Button1" Text="发送" Runat="server" OnClick="OnSend" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 240px"></asp:Button>
</form>
</body>
</HTML>
解决方案 »
- 页面刷新之后数据丢失
- asp.net中用web页面登录exchange邮箱
- 如何用javascript分别取出一个值中用逗号分隔的字符内容
- 我是个菜鸟,请各位提供几个学习asp.net比较好的网站。谢谢!
- 问一下,ASP.NET环境下有没有与ASP中的recordset对应的namespace ?
- 小鸟问题,刚注册不久没多少分。
- 急!!C# iframe 取值问题!!
- 请教:页面传参问题
- 求助:页面导到别的项目时,该页面继承的基类没有自动改变命名空间!!!
- Flexpapper不能动态加载swf
- VS.NET 2003中button的onclick调用javascript写的函数提示“并未定义该函数”。要怎么做.
- 重庆的程序员(或测试)来看看吧,好消息
mail.Send(mail);"//这里提示“c:\
SmtpMail大小写错了
第2:你这样如果本机没有邮件服务还是发布出去.
aMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
aMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strUserName); //set your username here
aMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Send.GetClientPWD() ); //set your password here
SmtpMail.SmtpServer = Send.GetSMTP();
using System.Web.Util