posts - 11,  comments - 4,  trackbacks - 1


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 MymailSys
{
 /// <summary>
 /// WebForm1 的摘要说明。
 /// </summary>
 public partial class WebMail : System.Web.UI.Page
 {
  protected System.Web.UI.HtmlControls.HtmlForm Form2;
 
  protected 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()
  {   

  }
  #endregion

  protected void btnSubmit_Click(object sender, System.EventArgs e)
  {
   System.Net.WebProxy proxy = new System.Net.WebProxy("192.168.0.1:80");
   proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
   System.Net.GlobalProxySelection.Select = proxy;
   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!="")
   {
    
    //以下代码适用于Framework1.1以上版本。
    //SmtpMail.SmtpServer = tbServer.Text;
//    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);
  }
 }
}

(from msdn 邵老师的讲座)

posted on 2006-11-22 16:18 sandboy 阅读(1883) 评论(0)  编辑 收藏

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-06-15 08:01 编辑过


相关链接:
 


<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

与我联系

搜索

 

常用链接

留言簿

随笔档案

文章分类

最新评论

阅读排行榜

评论排行榜