protected void btSubmit_Click(object sender, EventArgs e)
    
{
        
//设置MailMessage类的to属性所需的MailAddress
        MailAddress toAddress = new MailAddress(this.tbReceiver.Text);
        
//设置MailMessage类的from属性所需的MailAddress
        MailAddress fromAddress = new MailAddress(this.tbSender.Text);
        
//新建一个MailMessage类实例
        MailMessage message = new MailMessage(fromAddress, toAddress);
        
//设置这个实例的Subject属性
        message.Subject = this.tbSubject.Text;
        
//设置这个实例的Body属性
        message.Body = this.tbMessage.Text;
        
//添加附件
        
//获得文件
        HttpPostedFile postedFile = file.PostedFile;
        
//当有附件时
        if (postedFile.ContentLength != 0)
        
{
            
//声明一个Attachment类实例
            Attachment data = new Attachment(postedFile.FileName);
            message.Attachments.Add(data);
        }

        
//设置正文格式
        if (rblFormat.SelectedItem.Text == "纯文本格式")
            message.IsBodyHtml 
= false;
        
else
            message.IsBodyHtml 
= true;
        
//添加抄送地址
        if (this.tbCc.Text != "")
        
{
            MailAddress ccAddress 
= new MailAddress(this.tbCc.Text);
            message.CC.Add(ccAddress);
        }

        
//添加暗送地址
        if (this.tbBcc.Text != "")
        
{
            MailAddress bccAddress 
= new MailAddress(this.tbBcc.Text);
            message.Bcc.Add(bccAddress);
        }

        
//新建一个SmtpClient类的实例
        SmtpClient client = new SmtpClient();
        
//设置在本机smtp服务器中绑定的ip地址,本例为本机ip地址
        client.Host = "159.226.58.89";
        
//smtp端口,默认为25
        client.Port = 25;
        
//发送
        client.Send(message);
        
//发送完毕后提示
        Response.Write("<script language='javascript'>alert('发送成功')</script>");
    }
posted on 2007-05-27 01:03  小角色  阅读(679)  评论(0)    收藏  举报