发送邮件

None.gif using  System;
None.gif
using  System.Drawing;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Windows.Forms;
None.gif
using  System.Data;
None.gif
using  System.Web.Mail;
None.gif
None.gif
namespace  MyMail
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for Form1.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class Form1 : System.Windows.Forms.Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private System.Windows.Forms.Label label1;
InBlock.gif        
private System.Windows.Forms.Label label2;
InBlock.gif        
private System.Windows.Forms.Label label3;
InBlock.gif        
private System.Windows.Forms.Label label4;
InBlock.gif        
private System.Windows.Forms.TextBox txtSender;
InBlock.gif        
private System.Windows.Forms.TextBox txtRecipient;
InBlock.gif        
private System.Windows.Forms.TextBox txtSubject;
InBlock.gif        
private System.Windows.Forms.TextBox txtText;
InBlock.gif        
private System.Windows.Forms.TextBox txtAttachments;
InBlock.gif        
private System.Windows.Forms.Button btnAttachments;
InBlock.gif        
private System.Windows.Forms.Button btnSend;
InBlock.gif        
private System.Windows.Forms.OpenFileDialog openFileDialog1;
InBlock.gif        
private System.Windows.Forms.Button btnExit;
InBlock.gif
InBlock.gif        MailMessage message 
= new MailMessage();
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Required designer variable.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private System.ComponentModel.Container components = null;
InBlock.gif
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// Required for Windows Form Designer support
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif
InBlock.gif            
//
InBlock.gif            
// TODO: Add any constructor code after InitializeComponent call
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Clean up any resources being used.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        protected override void Dispose( bool disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if( disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (components != null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    components.Dispose();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.Dispose( disposing );
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Windows Form Designer generated code#region Windows Form Designer generated code
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// Required method for Designer support - do not modify
InBlock.gif        
/// the contents of this method with the code editor.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.label1 = new System.Windows.Forms.Label();
InBlock.gif            
this.label2 = new System.Windows.Forms.Label();
InBlock.gif            
this.label3 = new System.Windows.Forms.Label();
InBlock.gif            
this.label4 = new System.Windows.Forms.Label();
InBlock.gif            
this.txtSender = new System.Windows.Forms.TextBox();
InBlock.gif            
this.txtRecipient = new System.Windows.Forms.TextBox();
InBlock.gif            
this.txtSubject = new System.Windows.Forms.TextBox();
InBlock.gif            
this.txtText = new System.Windows.Forms.TextBox();
InBlock.gif            
this.txtAttachments = new System.Windows.Forms.TextBox();
InBlock.gif            
this.btnAttachments = new System.Windows.Forms.Button();
InBlock.gif            
this.btnSend = new System.Windows.Forms.Button();
InBlock.gif            
this.btnExit = new System.Windows.Forms.Button();
InBlock.gif            
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
InBlock.gif            
this.SuspendLayout();
InBlock.gif            
// 
InBlock.gif            
// label1
InBlock.gif            
// 
InBlock.gif
            this.label1.Location = new System.Drawing.Point(2416);
InBlock.gif            
this.label1.Name = "label1";
InBlock.gif            
this.label1.Size = new System.Drawing.Size(10416);
InBlock.gif            
this.label1.TabIndex = 0;
InBlock.gif            
this.label1.Text = "发件人:";
InBlock.gif            
// 
InBlock.gif            
// label2
InBlock.gif            
// 
InBlock.gif
            this.label2.Location = new System.Drawing.Point(2448);
InBlock.gif            
this.label2.Name = "label2";
InBlock.gif            
this.label2.Size = new System.Drawing.Size(10416);
InBlock.gif            
this.label2.TabIndex = 1;
InBlock.gif            
this.label2.Text = "收件人:";
InBlock.gif            
// 
InBlock.gif            
// label3
InBlock.gif            
// 
InBlock.gif
            this.label3.Location = new System.Drawing.Point(2480);
InBlock.gif            
this.label3.Name = "label3";
InBlock.gif            
this.label3.Size = new System.Drawing.Size(10416);
InBlock.gif            
this.label3.TabIndex = 2;
InBlock.gif            
this.label3.Text = "主题:";
InBlock.gif            
// 
InBlock.gif            
// label4
InBlock.gif            
// 
InBlock.gif
            this.label4.Location = new System.Drawing.Point(24112);
InBlock.gif            
this.label4.Name = "label4";
InBlock.gif            
this.label4.Size = new System.Drawing.Size(10424);
InBlock.gif            
this.label4.TabIndex = 3;
InBlock.gif            
this.label4.Text = "附件:";
InBlock.gif            
// 
InBlock.gif            
// txtSender
InBlock.gif            
// 
InBlock.gif
            this.txtSender.Location = new System.Drawing.Point(14416);
InBlock.gif            
this.txtSender.Name = "txtSender";
InBlock.gif            
this.txtSender.Size = new System.Drawing.Size(20821);
InBlock.gif            
this.txtSender.TabIndex = 5;
InBlock.gif            
this.txtSender.Text = "";
InBlock.gif            
// 
InBlock.gif            
// txtRecipient
InBlock.gif            
// 
InBlock.gif
            this.txtRecipient.Location = new System.Drawing.Point(14448);
InBlock.gif            
this.txtRecipient.Name = "txtRecipient";
InBlock.gif            
this.txtRecipient.Size = new System.Drawing.Size(20821);
InBlock.gif            
this.txtRecipient.TabIndex = 6;
InBlock.gif            
this.txtRecipient.Text = "";
InBlock.gif            
// 
InBlock.gif            
// txtSubject
InBlock.gif            
// 
InBlock.gif
            this.txtSubject.Location = new System.Drawing.Point(14480);
InBlock.gif            
this.txtSubject.Name = "txtSubject";
InBlock.gif            
this.txtSubject.Size = new System.Drawing.Size(20821);
InBlock.gif            
this.txtSubject.TabIndex = 7;
InBlock.gif            
this.txtSubject.Text = "";
InBlock.gif            
// 
InBlock.gif            
// txtText
InBlock.gif            
// 
InBlock.gif
            this.txtText.Location = new System.Drawing.Point(24184);
InBlock.gif            
this.txtText.Multiline = true;
InBlock.gif            
this.txtText.Name = "txtText";
InBlock.gif            
this.txtText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
InBlock.gif            
this.txtText.Size = new System.Drawing.Size(328104);
InBlock.gif            
this.txtText.TabIndex = 9;
InBlock.gif            
this.txtText.Text = "";
InBlock.gif            
// 
InBlock.gif            
// txtAttachments
InBlock.gif            
// 
InBlock.gif
            this.txtAttachments.Location = new System.Drawing.Point(144112);
InBlock.gif            
this.txtAttachments.Multiline = true;
InBlock.gif            
this.txtAttachments.Name = "txtAttachments";
InBlock.gif            
this.txtAttachments.ReadOnly = true;
InBlock.gif            
this.txtAttachments.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
InBlock.gif            
this.txtAttachments.Size = new System.Drawing.Size(20848);
InBlock.gif            
this.txtAttachments.TabIndex = 8;
InBlock.gif            
this.txtAttachments.Text = "";
InBlock.gif            
// 
InBlock.gif            
// btnAttachments
InBlock.gif            
// 
InBlock.gif
            this.btnAttachments.Location = new System.Drawing.Point(24304);
InBlock.gif            
this.btnAttachments.Name = "btnAttachments";
InBlock.gif            
this.btnAttachments.TabIndex = 10;
InBlock.gif            
this.btnAttachments.Text = "附件";
InBlock.gif            
this.btnAttachments.Click += new System.EventHandler(this.btnAttachments_Click);
InBlock.gif            
// 
InBlock.gif            
// btnSend
InBlock.gif            
// 
InBlock.gif
            this.btnSend.Location = new System.Drawing.Point(152304);
InBlock.gif            
this.btnSend.Name = "btnSend";
InBlock.gif            
this.btnSend.TabIndex = 11;
InBlock.gif            
this.btnSend.Text = "发送";
InBlock.gif            
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
InBlock.gif            
// 
InBlock.gif            
// btnExit
InBlock.gif            
// 
InBlock.gif
            this.btnExit.Location = new System.Drawing.Point(280304);
InBlock.gif            
this.btnExit.Name = "btnExit";
InBlock.gif            
this.btnExit.TabIndex = 12;
InBlock.gif            
this.btnExit.Text = "退出";
InBlock.gif            
this.btnExit.Click += new System.EventHandler(this.btnCancel_Click);
InBlock.gif            
// 
InBlock.gif            
// Form1
InBlock.gif            
// 
InBlock.gif
            this.AutoScaleBaseSize = new System.Drawing.Size(614);
InBlock.gif            
this.ClientSize = new System.Drawing.Size(368341);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
this.Controls.AddRange(new System.Windows.Forms.Control[] dot.gif{
InBlock.gif                                                                          
this.btnExit,
InBlock.gif                                                                          
this.btnSend,
InBlock.gif                                                                          
this.btnAttachments,
InBlock.gif                                                                          
this.txtText,
InBlock.gif                                                                          
this.txtAttachments,
InBlock.gif                                                                          
this.txtSubject,
InBlock.gif                                                                          
this.txtRecipient,
InBlock.gif                                                                          
this.txtSender,
InBlock.gif                                                                          
this.label4,
InBlock.gif                                                                          
this.label3,
InBlock.gif                                                                          
this.label2,
ExpandedSubBlockEnd.gif                                                                          
this.label1}
);
InBlock.gif            
this.Name = "Form1";
InBlock.gif            
this.Text = "E-Mailer";
InBlock.gif            
this.ResumeLayout(false);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// The main entry point for the application.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        [STAThread]
InBlock.gif        
static void Main() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Application.Run(
new Form1());
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btnCancel_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Application.Exit();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btnAttachments_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            openFileDialog1.ShowDialog();
InBlock.gif            MailAttachment attachment  
= new MailAttachment(openFileDialog1.FileName);
InBlock.gif            txtAttachments.Text 
= txtAttachments.Text + openFileDialog1.FileName;
InBlock.gif            message.Attachments.Add(attachment);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btnSend_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            message.From 
= txtSender.Text;
InBlock.gif            message.To 
= txtRecipient.Text;
InBlock.gif            message.Subject 
= txtSubject.Text;
InBlock.gif            message.Body 
= txtText.Text;
InBlock.gif            SmtpMail.Send(message);
InBlock.gif            MessageBox.Show(
"邮件成功发送!");
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
 
程序附图片如下






tubiao.jpg

转载于:https://www.cnblogs.com/army666/archive/2005/10/21/259247.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值