如何在ASP.NET中做收发邮箱?
请问:如何在ASP.NET中做收发邮箱功能?
------解决方案--------------------这个有两个选择,一个是.net本身的Mail类.一个是利用很流行的Jmail组件.
Jmail要方便一些,..net本身自带mail类资料很少,至少CSDN上比较少.
推荐在CSDN搜索Jmail
------解决方案--------------------我参考了一个发送邮件的vs2005
cs:
using System.Web.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click ( object sender, EventArgs e )
{
MailMessage aMail = new MailMessage ();
aMail.To = TextBox1.Text;
aMail.From = TextBox2.Text;
aMail.Subject = TextBox3.Text;
aMail.Body = TextBox4.Text;
aMail.Priority = ( MailPriority ) DropDownList1.SelectedIndex;
aMail.BodyFormat = ( MailFormat ) DropDownList2.SelectedIndex;
DropDownList1.SelectedIndex = 1;
DropDownList2.SelectedIndex = 0;
if ( File1.PostedFile.FileName != " " )
{
string fileName = File1.PostedFile.FileName;
fileName = fileName.Substring ( fileName.LastIndexOf ( @ "\ " ) );
fileName = Server.MapPath ( " ") + "/temp/ " + fileName;
//fileName = HttpRuntime.AppDomainAppPath + "/temp/ " + fileName;
File1.PostedFile.SaveAs ( fileName );
aMail.Attachments.Add ( new MailAttachment ( fileName ) );
}
string result = " ";
try
{
SmtpMail.Send ( aMail );
result = "Email success ";
}
catch ( Exception ex )
{
result = "Email fail " + ex.Message;
}
Response.Write ( " <script language= 'JavaScript '> window.alert( ' " + result + " '); </script> " );
}
}
aspx:
<body>
<form id= "form1 " runat= "server ">
<div align= "center ">
<asp:TextBox ID= "TextBox1 " runat= "server " Width= "281px "> </asp:TextBox> <br>
<asp:TextBox ID= "TextBox2 " runat= "server " Width= "281px "> </asp:TextBox> <br>
<asp:TextBox ID= "TextBox3 " runat= "server " Width= "281px "> </asp:TextBox> <br>
<input id= "File1 " type= "file " style= "width: 286px " runat= "server " /> <br>
<asp:TextBox ID= "TextBox4 " runat= "server " Height= "188px " Width= "281px "> </asp:TextBox> <br>
<asp:DropDownList ID= "DropDownList1 " runat= "server ">
<asp:ListItem Value= "High "> High </asp:ListItem>
<asp:ListItem Value= "Middle " Selected= "True "> Middle </asp:ListItem>
<asp:ListItem Value= "Low "> Low </asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID= "DropDownList2 " runat= "server ">
<asp:ListItem Value= "TXT " Selected= "True "> TXT </asp:ListItem>
<asp:ListItem Value= "HTML "> HTML </asp:ListItem>
</asp:DropDownList> <br>
&