ASP.NET中发送邮件

private void btnSubmit_Click(object sender, System.EventArgs e)

{

//SmtpMail.Send("shaozhd@263.net","shaozhd@263.net","Test","Hello"); MailMessage m = new MailMessage();

m.From = tbFrom.Text;

m.To = tbTo.Text;

m.Subject = tbSubject.Text;

m.Body = tbBody.Text;

//优先级

switch(ddlp.SelectedIndex)

{

case 0:

m.Priority = MailPriority.High;

break;

case 1:

m.Priority = MailPriority.Low;

break;

default:

m.Priority = MailPriority.Normal;

break;

}

//格式

if(ddlp.SelectedIndex==0)

m.BodyFormat = MailFormat.Text;

else

m.BodyFormat = MailFormat.Html;

//以下设置服务器

if(tbServer.Text!="")

{

SmtpMail.SmtpServer = tbServer.Text;

//以下代码适用于Framework1.1以上版本。

m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",

"1"); //basic authentication

m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",

tbUserName.Text); //set your username here

m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",

tbPass.Text); //set your password here

}

//以下处理附件

string strFileName = FileSelect.PostedFile.FileName;

if(strFileName!="")

m.Attachments.Add(new MailAttachment(strFileName));

SmtpMail.Send(m);

}

//Socket技术可实现邮件的接收