Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Form1.cs
Package: VC#.NET范例.rar [view]
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 11k
Category:
ADO-ODBC
Development Platform:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Web.Mail;
- namespace ch7_4
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.TextBox textBox2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.TextBox textBox3;
- private System.Windows.Forms.TextBox textBox4;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.RichTextBox richTextBox1;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.RadioButton radioButton1;
- private System.Windows.Forms.RadioButton radioButton2;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.TextBox textBox5;
- private System.Windows.Forms.ComboBox comboBox1;
- private System.Windows.Forms.Label label6;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form1()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.label1 = new System.Windows.Forms.Label();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.button1 = new System.Windows.Forms.Button();
- this.richTextBox1 = new System.Windows.Forms.RichTextBox();
- this.button2 = new System.Windows.Forms.Button();
- this.radioButton1 = new System.Windows.Forms.RadioButton();
- this.radioButton2 = new System.Windows.Forms.RadioButton();
- this.label5 = new System.Windows.Forms.Label();
- this.textBox5 = new System.Windows.Forms.TextBox();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.label6 = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(24, 28);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(56, 16);
- this.label1.TabIndex = 0;
- this.label1.Text = "收件人";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(112, 24);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(256, 21);
- this.textBox1.TabIndex = 1;
- this.textBox1.Text = "";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(24, 60);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(56, 16);
- this.label2.TabIndex = 2;
- this.label2.Text = "抄送";
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(112, 56);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(256, 21);
- this.textBox2.TabIndex = 3;
- this.textBox2.Text = "";
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(24, 90);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(72, 16);
- this.label3.TabIndex = 4;
- this.label3.Text = "主题";
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(24, 124);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(56, 16);
- this.label4.TabIndex = 5;
- this.label4.Text = "附件";
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(112, 88);
- this.textBox3.Name = "textBox3";
- this.textBox3.Size = new System.Drawing.Size(256, 21);
- this.textBox3.TabIndex = 6;
- this.textBox3.Text = "";
- //
- // textBox4
- //
- this.textBox4.Location = new System.Drawing.Point(112, 120);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(256, 21);
- this.textBox4.TabIndex = 7;
- this.textBox4.Text = "";
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(384, 120);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(72, 23);
- this.button1.TabIndex = 8;
- this.button1.Text = "添加附件";
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // richTextBox1
- //
- this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.richTextBox1.Location = new System.Drawing.Point(0, 237);
- this.richTextBox1.Name = "richTextBox1";
- this.richTextBox1.Size = new System.Drawing.Size(472, 184);
- this.richTextBox1.TabIndex = 9;
- this.richTextBox1.Text = "";
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(384, 196);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(72, 23);
- this.button2.TabIndex = 10;
- this.button2.Text = "发送邮件";
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // radioButton1
- //
- this.radioButton1.Checked = true;
- this.radioButton1.Location = new System.Drawing.Point(208, 196);
- this.radioButton1.Name = "radioButton1";
- this.radioButton1.Size = new System.Drawing.Size(72, 24);
- this.radioButton1.TabIndex = 11;
- this.radioButton1.TabStop = true;
- this.radioButton1.Text = "文本方式";
- this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
- //
- // radioButton2
- //
- this.radioButton2.Location = new System.Drawing.Point(280, 196);
- this.radioButton2.Name = "radioButton2";
- this.radioButton2.Size = new System.Drawing.Size(72, 24);
- this.radioButton2.TabIndex = 12;
- this.radioButton2.Text = "html方式";
- this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(24, 164);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(56, 16);
- this.label5.TabIndex = 13;
- this.label5.Text = "发件人";
- //
- // textBox5
- //
- this.textBox5.Location = new System.Drawing.Point(112, 160);
- this.textBox5.Name = "textBox5";
- this.textBox5.Size = new System.Drawing.Size(256, 21);
- this.textBox5.TabIndex = 14;
- this.textBox5.Text = "";
- //
- // comboBox1
- //
- this.comboBox1.Items.AddRange(new object[] {
- "正常",
- "高",
- "低"});
- this.comboBox1.Location = new System.Drawing.Point(112, 198);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(72, 20);
- this.comboBox1.TabIndex = 15;
- this.comboBox1.Text = "正常";
- //
- // label6
- //
- this.label6.Location = new System.Drawing.Point(24, 202);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(48, 16);
- this.label6.TabIndex = 16;
- this.label6.Text = "优先级";
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(472, 421);
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.label6,
- this.comboBox1,
- this.textBox5,
- this.label5,
- this.radioButton2,
- this.radioButton1,
- this.button2,
- this.richTextBox1,
- this.button1,
- this.textBox4,
- this.textBox3,
- this.label4,
- this.label3,
- this.textBox2,
- this.label2,
- this.textBox1,
- this.label1});
- this.Name = "Form1";
- this.Text = "发送邮件";
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void button2_Click(object sender, System.EventArgs e)
- {
- try
- {
- MailMessage message=new MailMessage();
- if (this.textBox1.Text!="")
- {
- message.To=this.textBox1.Text;
- //设置正文内容类型
- message.BodyFormat=MailFormat.Text;
- if (this.radioButton2.Checked==true)
- {
- message.BodyFormat=MailFormat.Html;
- }
- //设置邮件征文的编码类型
- message.BodyEncoding=System.Text.Encoding.UTF8;
- //设置邮件主题
- message.Subject=this.textBox3.Text;
- //设置邮件正文
- message.Body=this.richTextBox1.Text;
- //判断是否有附件
- if (this.textBox4.Text!="")
- {
- //构造一个附件对象
- MailAttachment attach=new MailAttachment(this.textBox4.Text);
- //添加附件
- message.Attachments.Add(attach);
- }
- //判断是否有抄送
- if (this.textBox3.Text!="")
- {
- message.Cc=this.textBox3.Text;
- }
- //设置发件人
- message.From=this.textBox5.Text;
- //设置优先级
- int i=this.comboBox1.SelectedIndex;
- if (i==0)
- {
- message.Priority=MailPriority.Normal;
- }
- if (i==1)
- {
- message.Priority=MailPriority.High;
- }
- if (i==2)
- {
- message.Priority=MailPriority.Low;
- }
- //发送邮件
- SmtpMail.Send(message);
- MessageBox.Show("邮件发送已经成功","恭喜"
- ,MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- else
- {
- MessageBox.Show("未指定收件人地址","警告",
- MessageBoxButtons.OK,MessageBoxIcon.Warning);
- }
- }
- catch( Exception error)
- {
- MessageBox.Show("邮件发送失败信息:"+error.Message,"失败"
- ,MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- OpenFileDialog oFileDialog=new OpenFileDialog();
- if (oFileDialog.ShowDialog()==DialogResult.OK)
- {
- this.textBox4.Text=oFileDialog.FileName;
- }
- }
- private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
- {
- if (this.radioButton1.Checked==true)
- {
- //是两个单选按钮状态不同
- this.radioButton2.Checked=false;
- }
- }
- private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
- {
- if (this.radioButton2.Checked==true)
- {
- //使两个单选按钮状态不同
- this.radioButton1.Checked=false;
- }
- }
- }
- }