这是VB的例子。C#的你参考着自已弄吧。
<%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="False" Strict="True" %>
<%@ Import Namespace="System.Web.Mail" %>
<script language="VB" runat=server>
Sub Page_load(Sender as Object, E as EventArgs)
If request.form("EmailAddress") = "" Then
dim strResponse as string = "<h2>Send Email using ASP.NET formatted in HTML</h2>"
lblMessage.Text = strResponse
Else
dim strResponse as string = "You just sent an email message formatted in HTML to:<br><h2>" & request("EmailAddress") & "</h2>"
lblMessage.Text = strResponse
End If
End Sub
Sub btn_Click(sender as Object, e as System.EventArgs) If request.form("EmailAddress") <> ""
Dim mail As New MailMessage
mail.From = "[email protected]"
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from ASPFree.com using ASP.NET and Cdonts<br><a href='http://aspfree.com/aspnet/email.aspx'>Wonder how this is done?</a><br><br><a href='http://aspfree.com/aspnet/setupcdonts.aspx'>Wonder How to setup CDONTS?</a>"
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "LocalServerName"
SmtpMail.Send(mail)
End If
End Sub</script>
<html>
<head>
</head>
<body>
<h1 align="center">Sending Email via ASP.NET and CDONTS..</h1>
<b><a href="/aspnet/setupcdonts.aspx">How do I setup my server to use CDONTS?</a></b>
<br />
<br />
<a href="/allzips/emaildotnet.zip"><img src="http://aspfree.com/images/downloadcode.gif" border="0"></a>
<br />
<br />
<asp:Label id="lblMessage" Font-Name="Verdana" Width="400px" BorderStyle="solid" BorderColor="#cccccc" runat="server"/><form method="post" name="form1" runat="server" runat="server">
Email Address:<input type="text" name="EmailAddress" size="30" value=""><br><br>
<input type="Submit" id="btnSubmit" OnServerClick="btn_Click" value="Sending Email with ASP.NET" name="b1" runat="server" />
</form>
</body>
</html>
<%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="False" Strict="True" %>
<%@ Import Namespace="System.Web.Mail" %>
<script language="VB" runat=server>
Sub Page_load(Sender as Object, E as EventArgs)
If request.form("EmailAddress") = "" Then
dim strResponse as string = "<h2>Send Email using ASP.NET formatted in HTML</h2>"
lblMessage.Text = strResponse
Else
dim strResponse as string = "You just sent an email message formatted in HTML to:<br><h2>" & request("EmailAddress") & "</h2>"
lblMessage.Text = strResponse
End If
End Sub
Sub btn_Click(sender as Object, e as System.EventArgs) If request.form("EmailAddress") <> ""
Dim mail As New MailMessage
mail.From = "[email protected]"
mail.To = request.form("EmailAddress")
mail.Subject = "Message sent using ASP.NET and CDONTS"
mail.Body = "HTML Message sent from ASPFree.com using ASP.NET and Cdonts<br><a href='http://aspfree.com/aspnet/email.aspx'>Wonder how this is done?</a><br><br><a href='http://aspfree.com/aspnet/setupcdonts.aspx'>Wonder How to setup CDONTS?</a>"
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "LocalServerName"
SmtpMail.Send(mail)
End If
End Sub</script>
<html>
<head>
</head>
<body>
<h1 align="center">Sending Email via ASP.NET and CDONTS..</h1>
<b><a href="/aspnet/setupcdonts.aspx">How do I setup my server to use CDONTS?</a></b>
<br />
<br />
<a href="/allzips/emaildotnet.zip"><img src="http://aspfree.com/images/downloadcode.gif" border="0"></a>
<br />
<br />
<asp:Label id="lblMessage" Font-Name="Verdana" Width="400px" BorderStyle="solid" BorderColor="#cccccc" runat="server"/><form method="post" name="form1" runat="server" runat="server">
Email Address:<input type="text" name="EmailAddress" size="30" value=""><br><br>
<input type="Submit" id="btnSubmit" OnServerClick="btn_Click" value="Sending Email with ASP.NET" name="b1" runat="server" />
</form>
</body>
</html>
解决方案 »
- 吃饭时间请教,TREEVIEW应用的小问题
- 主线程强制关闭,子线程用不用管了
- object 賦值不成功?
- 关于login控件与数据库的连接时遇到的问题
- 请问怎样实现这样的人员排班表功能?不求有代码,只求思路,谢谢
- 急!!!C#左边treeview打开右边tabcontrol问题!!!!
- 网页附件目标另存为可以下载WebClient下载为0 k
- 请教 Form 的 MaximizeBox 属性问题!
- Toolbar和freetextbox一起用的时候会有问题?
- 小弟我初学WinForm,那位大侠能谈谈它和WebForm有何区别?
- 菜鸟问题,送分
- 关于ProcessBar进度条的使用!请高手帮忙!
From 源地址
To 目的地址
Subject 邮件主题
Priority 邮件优先级 ( High , Low , Normal )
Attachments 附件
Bcc 暗送地址
Cc 抄送地址
Body 邮件内容主体
Bodyformat 邮件格式( Html , Text )
Bodyencoding 邮件编码( Base64 , Uuencode )
在程序中,具体的实现语句如下:MailMessage aMessage = new MailMessage ( ) ;
//新建一个MailMessage对象
aMessage.From = FromTextBox.Text ;
//定义发信人地址,如果是多人,可以用","分开
aMessage.To = ToTextBox.Text ;
//定义收信人地址,如果是多人,可以用","分开
aMessage.Cc = CCTextBox.Text ;
//定义抄送人地址,如果是多人,可以用","分开
aMessage.Bcc = BCCTextBox.Text ;
//定义暗送人地址,如果是多人,可以用","分开
aMessage.Subject = SubjectTextBox.Text ;
//定义邮件的主题
aMessage.Body = MessageTextBox.Text ;
//定义邮件的内容
if ( AttachmentTextBox.Text.Length > 0 )
aMessage.Attachments.Add ( new MailAttachment ( AttachmentTextBox.Text , MailEncoding.Base64 ) ) ;
//给邮件增加一个附件 注:"="右边是程序中定义的文本框的"Text"值。 (3).用SmtpMail对象正确发送电子邮件: 在Visual C#中调用SmtpMail对象的Send ( )方法有多种方式。本文介绍的只是其中的一种比较常用的调用方式,即:SmtpMail.Send ( MailMessage对象 )。在程序中的实现语句如下: SmtpMail.Send ( aMessage ) ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Web ;
using System.Web.Mail ;
//导入程序中使用到的名称空间
public class Form1 : Form
{
private Label label1 ;
private Label label2 ;
private Label label3 ;
private Button SendButton ;
private Button ExitButton ;
private TextBox FromTextBox ;
private TextBox ToTextBox ;
private TextBox SubjectTextBox ;
private TextBox MessageTextBox ;
private TextBox CCTextBox ;
private Label CCLabel ;
private TextBox BCCTextBox ;
private Label label4 ;
private Label label5 ;
private Button BrowseButton ;
private OpenFileDialog openFileDialog1 ;
private TextBox AttachmentTextBox ;
private System.ComponentModel.Container components = null ;
public Form1 ( )
{
InitializeComponent ( ) ;
}
//清除在程序中使用的所有资源
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose ( ) ;
}
}
base.Dispose ( disposing ) ;
}
private void InitializeComponent ( )
{
MessageTextBox = new TextBox ( ) ;
ToTextBox = new TextBox ( ) ;
SendButton = new Button ( ) ;
ExitButton = new Button ( ) ;
FromTextBox = new TextBox ( ) ;
label1 = new Label ( ) ;
SubjectTextBox = new TextBox ( ) ;
label2 = new Label ( ) ;
label3 = new Label ( ) ;
CCTextBox = new TextBox ( ) ;
CCLabel = new Label ( ) ;
BCCTextBox = new TextBox ( ) ;
label4 = new Label ( ) ;
label5 = new Label ( ) ;
AttachmentTextBox = new TextBox ( ) ;
BrowseButton = new Button ( ) ;
openFileDialog1 = new OpenFileDialog ( ) ; FromTextBox.Location = new System.Drawing.Point ( 96 , 16 ) ;
FromTextBox.Name = "FromTextBox" ;
FromTextBox.Size = new System.Drawing.Size ( 240 , 20 ) ;
FromTextBox.TabIndex = 0 ;
FromTextBox.Text = "" ; ToTextBox.Location = new System.Drawing.Point ( 96 , 53 ) ;
ToTextBox.Name = "ToTextBox" ;
ToTextBox.Size = new System.Drawing.Size ( 240 , 20 ) ;
ToTextBox.Text = "" ;
ToTextBox.TabIndex = 1 ; CCTextBox.Location = new System.Drawing.Point ( 96 , 88 ) ;
CCTextBox.Name = "CCTextBox" ;
CCTextBox.Size = new System.Drawing.Size ( 240 , 20 ) ;
CCTextBox.TabIndex = 2 ;
CCTextBox.Text = "" ; BCCTextBox.Location = new System.Drawing.Point ( 96 , 120 ) ;
BCCTextBox.Name = "BCCTextBox" ;
BCCTextBox.Size = new System.Drawing.Size ( 240 , 20 ) ;
BCCTextBox.TabIndex = 3 ;
BCCTextBox.Text = "" ; SubjectTextBox.Location = new System.Drawing.Point ( 96 , 152 ) ;
SubjectTextBox.Name = "SubjectTextBox" ;
SubjectTextBox.Size = new System.Drawing.Size ( 240 , 20 ) ;
SubjectTextBox.TabIndex = 4 ;
SubjectTextBox.Text = "" ; AttachmentTextBox.Location = new System.Drawing.Point ( 96 , 184 ) ;
AttachmentTextBox.Name = "AttachmentTextBox" ;
AttachmentTextBox.Size = new System.Drawing.Size ( 168 , 20 ) ;
AttachmentTextBox.TabIndex = 5 ;
AttachmentTextBox.Text = "" ; MessageTextBox.Location = new System.Drawing.Point ( 8 , 216 ) ;
MessageTextBox.Multiline = true ;
MessageTextBox.Name = "MessageTextBox" ;
MessageTextBox.Size = new System.Drawing.Size ( 320 , 152 ) ;
MessageTextBox.Text = "" ;
MessageTextBox.TabIndex = 6 ; BrowseButton.Location = new System.Drawing.Point ( 280 , 184 ) ;
BrowseButton.Name = "BrowseButton";
BrowseButton.Size = new System.Drawing.Size ( 56 , 24 ) ;
BrowseButton.Text = "浏览文件" ;
BrowseButton.TabIndex = 7 ;
BrowseButton.Click += new System.EventHandler ( BrowseButton_Click ) ; SendButton.Location = new System.Drawing.Point ( 64 , 380 ) ;
SendButton.Name = "SendButton" ;
SendButton.Size = new System.Drawing.Size ( 72 , 24 ) ;
SendButton.Text = "发送邮件" ;
SendButton.TabIndex = 8 ;
SendButton.Click += new System.EventHandler ( SendButton_Click ) ; ExitButton.Location = new System.Drawing.Point ( 200 , 380 ) ;
ExitButton.Name = "ExitButton" ;
ExitButton.Size = new System.Drawing.Size ( 72 , 24 ) ;
ExitButton.Text = "退出程序";
ExitButton.TabIndex = 9 ;
ExitButton.Click += new System.EventHandler ( ExitButton_Click ) ; label1.Font = new System.Drawing.Font ( "宋体", 9F );
label1.Location = new System.Drawing.Point ( 48 , 16 ) ;
label1.Name = "label1" ;
label1.Size = new System.Drawing.Size ( 48 , 16 ) ;
label1.Text = "发信人:" ; label2.Font = new System.Drawing.Font ( "宋体", 9F );
label2.Location = new System.Drawing.Point ( 48 , 53 ) ;
label2.Name = "label2" ;
label2.Size = new System.Drawing.Size ( 48 , 16 ) ;
label2.Text = "收信人:" ;
label3.Font = new System.Drawing.Font ( "宋体", 9F ) ;
label3.Location = new System.Drawing.Point ( 48 , 152 ) ;
label3.Name = "label3" ;
label3.Size = new System.Drawing.Size ( 48 , 16 ) ;
label3.Text = "主 题:" ; CCLabel.Font = new System.Drawing.Font ( "宋体", 9F ) ;
CCLabel.Location = new System.Drawing.Point ( 48 , 88 ) ;
CCLabel.Name = "CCLabel" ;
CCLabel.Size = new System.Drawing.Size ( 48 , 16 ) ;
CCLabel.Text = "抄 送:" ; label4.Font = new System.Drawing.Font ( "宋体", 9F ) ;
label4.Location = new System.Drawing.Point ( 48 , 120 ) ;
label4.Name = "label4" ;
label4.Size = new System.Drawing.Size ( 48 , 16 ) ;
label4.Text = "暗 送:" ; label5.Font = new System.Drawing.Font ( "宋体", 9F ) ;
label5.Location = new System.Drawing.Point ( 48 , 184 ) ;
label5.Name = "label5" ;
label5.Size = new System.Drawing.Size ( 48 , 16 ) ;
label5.Text = "附 件:" ; openFileDialog1.Title = "选择文件作为邮件的附件:" ; this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.ClientSize = new System.Drawing.Size ( 344 , 413 ) ;
this.Controls.Add ( BrowseButton ) ;
this.Controls.Add ( AttachmentTextBox ) ;
this.Controls.Add ( label5 ) ;
this.Controls.Add ( label4 ) ;
this.Controls.Add ( BCCTextBox ) ;
this.Controls.Add ( CCLabel ) ;
this.Controls.Add ( CCTextBox ) ;
this.Controls.Add ( ExitButton ) ;
this.Controls.Add ( SendButton ) ;
this.Controls.Add ( label3 ) ;
this.Controls.Add ( label2 ) ;
this.Controls.Add ( label1 ) ;
this.Controls.Add ( SubjectTextBox ) ;
this.Controls.Add ( ToTextBox ) ;
this.Controls.Add ( FromTextBox ) ;
this.Controls.Add ( MessageTextBox ) ;
this.Name = "Form1" ;
this.Text = "用Visual C#做邮件发送软件!" ;
this.ResumeLayout ( false ); }
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
} private void SendButton_Click ( object sender , System.EventArgs e )
{
try
{
MailMessage aMessage = new MailMessage ( ) ;
//新建一个MailMessage对象
aMessage.From = FromTextBox.Text ;
//定义发信人地址,如果是多人,可以用","分开
aMessage.To = ToTextBox.Text ;
//定义收信人地址,如果是多人,可以用","分开
aMessage.Cc = CCTextBox.Text ;
//定义抄送人地址,如果是多人,可以用","分开
aMessage.Bcc = BCCTextBox.Text ;
//定义暗送人地址,如果是多人,可以用","分开
aMessage.Subject = SubjectTextBox.Text ;
//定义邮件的主题
aMessage.Body = MessageTextBox.Text ;
//定义邮件的内容
if ( AttachmentTextBox.Text.Length > 0 )
aMessage.Attachments.Add ( new MailAttachment ( AttachmentTextBox.Text , MailEncoding.Base64 ) ) ;
//给邮件增加一个附件
SmtpMail.Send ( aMessage ) ;
//发送电子邮件
MessageBox.Show( "电子邮件已经发送到->" + ToTextBox.Text ) ;
}
catch
/// 发送邮件
/// </summary>
/// <param name="bcc"></param>
/// <param name="body">信的内容</param>
/// <param name="cc"></param>
/// <param name="from">发信人的地址</param>
/// <param name="subject">主题</param>
/// <param name="to">收信人的地址</param>
/// <returns>成功与否</returns>
[WebMethod]
public bool SendingMail (string from,string to,string cc,string bcc,string subject,string body)
{
try
{
MailMessage aMessage = new MailMessage();
aMessage.From = from;
aMessage.To = to;
aMessage.Cc = cc;
aMessage.Bcc = bcc;
aMessage.Subject = subject;
aMessage.Body = body;SmtpMail.Send ( aMessage );
return true;
}
catch
{
return false;
}
}请先引用:
using System.Web.Mail;
================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]
<% @ Import Namespace="System.Web.Mail" %>
<Script Language="C#" Runat="Server">
public void Mail_Send(Object src,EventArgs e)
{
//创建MailMessage对象
MailMessage MyMsg = new MailMessage();
MyMsg.From = tbFrom.Text;
MyMsg.To = tbTo.Text;
MyMsg.Subject = tbSubject.Text;
MyMsg.Priority = (MailPriority)ddlPriority.SelectedIndex;
MyMsg.BodyFormat= (MailFormat)ddlBodyFormat.SelectedIndex;
MyMsg.Body = tbBody.Text;
//如果有附件则上传
HttpPostedFile hpfFile = AttachFile.PostedFile;
if(hpfFile.FileName!="")
{
//有附件,则上传到Temp目录中
//取得文件名(不含路径)
char[] de = {'\\'};
string[] AFilename = hpfFile.FileName.Split(de);
string strFilename = AFilename[AFilename.Length-1];
string strPath = Server.MapPath(".")+"\\Temp\\"+strFilename;
hpfFile.SaveAs(strPath);
//添加附件
MyMsg.Attachments.Add(new MailAttachment(strPath));
} try
{
//发送
SmtpMail.Send(MyMsg);
lblShowMsg.Text ="发送成功";
tbTo.Text = "";
tbSubject.Text = "";
tbBody.Text = "";
ddlPriority.SelectedIndex = 1;
ddlBodyFormat.SelectedIndex = 0;
}
catch(Exception ee)
{
lblShowMsg.Text = "发送失败:"+ee.ToString();
}
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form Enctype="multipart/form-data" runat="server">
<b>演示发送邮件附件</b>
<table border=1>
<tr><td colspan="2"><b>功能强大的邮件发送</b></td></tr>
<tr><td colspan="2"><asp:Label id="lblShowMsg" ForeColor="red" runat="server" /></td></tr>
<tr><td>收件人:</td><td><asp:TextBox id="tbTo" runat="server" /></td></tr>
<tr><td>发件人:</td><td><asp:TextBox id="tbFrom" runat="server" /></td></tr>
<tr><td>邮件主题:</td><td><asp:TextBox id="tbSubject" runat="server" /></td></tr>
<tr>
<td>优先级: <asp:DropDownList id="ddlPriority" runat="server">
<asp:ListItem Value="High">高</asp:ListItem>
<asp:ListItem Value="Normal" Selected>普通</asp:ListItem>
<asp:ListItem Value="Low">低</asp:ListItem>
</asp:DropDownList>
</td>
<td>邮件格式:<asp:DropDownList id="ddlBodyFormat" runat="server">
<asp:ListItem Value="Text">文本格式</asp:ListItem>
<asp:ListItem Value="Html">HTML格式</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr><td colspan="2">邮件内容:</td></tr>
<tr><td colspan="2"><asp:TextBox TextMode="MultiLine" Rows="5" Columns="50" id="tbBody" runat="server" /></td></tr>
<tr><td>邮件附件:</td><td><input type="file" id="AttachFile" runat="server" /></td></tr>
<tr><td><asp:Button id="btnSend" Text="发送" OnClick="Mail_Send" runat="server" /></td></tr>
</table>
</form>
</body>
</html>
using System.Web ;
using System.Web.Mail ;
在类或者命名空间不存在
为什么????
正式版的命名空间不知道是不是变了
======================
- 微软全球技术中心本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
======================
private void button1_Click(object sender, System.EventArgs e)
{
try
{
if(textBox1.Text!="")
{
aa.To=textBox1.Text;}
else{
MessageBox.Show("请输入收件人地址");
} if(textBox2.Text!=""){
aa.Cc=textBox2.Text;}
if(textBox3.Text!=""){
aa.Bcc=textBox3.Text;}
if(textBox4.Text!="")
{
aa.From=textBox4.Text;}
else{MessageBox.Show("请输入发件人地址");}
aa.Subject=textBox5.Text;
aa.Body=richTextBox1.Text;
if(radioButton1.Checked)
{
aa.Priority=MailPriority.High;
}
else if(radioButton2.Checked)
{
aa.Priority=MailPriority.Low;
}
else if(radioButton3.Checked)
{
aa.Priority=MailPriority.Normal;
}
else{aa.Priority=MailPriority.Normal;}
SmtpMail.Send(aa); }
catch(Exception ee){MessageBox.Show(ee.Message);}
} private void button2_Click(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
bb=new MailAttachment(openFileDialog1.FileName,System.Web.Mail.MailEncoding.UUEncode);
aa.Attachments.Add(bb);} } private void button3_Click(object sender, System.EventArgs e)
{
aa.Attachments.Clear(); }
}
}
System.Web.Mail.MailMessage message=new MailMessage();
message.From="[email protected]";
message.Subject="计算机清单";
message.To="[email protected]";
message.Attachments.Add(new MailAttachment("d:\\studio\\PCList.htm"));
SmtpMail.SmtpServer="127.0.0.1"; //服务器IP地址
SmtpMail.Send(message);
System.Web.Mail.MailMessage message=new MailMessage();
message.From="[email protected]";
message.Subject="计算机清单";
message.To="[email protected]";
message.Attachments.Add(new MailAttachment("d:\\studio\\PCList.htm"));
SmtpMail.SmtpServer="127.0.0.1"; //服务器IP地址
SmtpMail.Send(message);
{
private TcpClient tcpC;
private string sTo;
private string sFrom;
private string sSubject;
private string sBody; public string to
{
get
{
return sTo;
} set
{
sTo=value;
}
} public string from
{
get
{
return sFrom;
} set
{
sFrom=value;
}
} public string subject
{
get
{
return sSubject;
} set
{
sSubject=value;
}
} public string body
{
get
{
return sBody;
} set
{
sBody=value;
}
}
public SMTPMail()
{
tcpC=new TcpClient();
init();
} private void init()
{
sTo="";
sFrom="";
sSubject="";
sBody="";
} public string send(string sHost)
{
string sData;
string sErr;
string sRead;
try
{
tcpC.Connect(sHost,25);
NetworkStream s=tcpC.GetStream();
sRead=response(s);
if(sRead=="220")
{
sData="helo me\r\n";
sErr=sendMsg(s,sData,"250");
if(sErr=="")
{
sData="mail from:" + sFrom + "\r\n";
sErr=sendMsg(s,sData,"250");
if(sErr=="")
{
sData="rcpt to:" + sTo + "\r\n";
sErr=sendMsg(s,sData,"250");
if(sErr=="")
{
sData="data\r\n";
sErr=sendMsg(s,sData,"354");
if(sErr=="")
{
sData="subject:" + sSubject + "\r\nto:" + sTo + "\r\nfrom:" + sFrom + "\r\nMIME-Version:1.0\r\nContent-Type:text/plain charset=\"gb2312\"\r\n\r\n" + sBody + "\r\n.\r\n";
sErr=sendMsg(s,sData,"250");
if(sErr=="")
{
sData="noop\r\n";
sErr=sendMsg(s,sData,"250");
if(sErr=="")
{
sData="quit\r\n";
sErr=sendMsg(s,sData,"221");
if(sErr=="")
{
// tcpC.Close();
init();
return "";
}
else
{
return sErr;
}
}
else
{
return sErr;
}
}
else
{
return sErr;
}
}
else
{
return sErr;
}
}
else
{
return sErr;
}
}
else
{
return sErr;
}
}
else
{
return sErr; }
}
else
{
return "连接错误";
}
}
catch(Exception e)
{
return e.Message;
}
finally
{
tcpC.Close();
}
} private string sendMsg(NetworkStream s,string sMsg,string sCom)
{
string sErr;
string sTemp;
try
{
sErr=write(s,sMsg);
if(sErr=="")
{
sTemp=response(s);
if(sTemp==sCom)
return "";
else
return "服务器未能得到数据\"" + sMsg + "\"!";
}
else
{
return "发送数据\"" + sMsg + "\"时出错!";
}
}
catch(Exception e)
{
return e.Message;
}
}
private string response(NetworkStream s)
{
byte[] buff=new byte[1024];
try
{
int iCount=s.Read(buff,0,buff.Length);
string sTemp;
if(iCount>0)
{
sTemp=Encoding.Default.GetString(buff);
return sTemp.Substring(0,3);
}
else
{
return "";
}
}
catch
{
return "";
}
} private string write(NetworkStream s,string sData)
{
try
{
byte[] buff=Encoding.Default.GetBytes(sData.ToCharArray());
s.Write(buff,0,buff.Length);
return "";
}
catch(Exception e)
{
return e.Message;
}
} }