C# 常见面试题2
1、树加载
2、邮件发送
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public partial class FrmSendMail : Form { private string mail; public FrmSendMail(string mail) { this.mail = mail; InitializeComponent(); } private void FrmSendMail_Load(object sender, EventArgs e) { txtTo.Text = this.mail; } private void btnSend_Click(object sender, EventArgs e) { MailMessage mail = new MailMessage(); //发件人 mail.From = new MailAddress("nll@mysite","管理员"); //收件人 mail.To.Add(new MailAddress(txtTo.Text)); //主题 mail.Subject = txtSubject.Text; //内容 mail.Body = txtBody.Text; // using (SmtpClient sc = new SmtpClient("127.0.0.1", 25)) { sc.Credentials = new NetworkCredential("nll", "nll"); try { sc.Send(mail); MessageBox.Show("发送成功"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //////////////////////////////////////////////////////////////////////////////// // //.net中使用的默认编码都是utf-8 // //webmail里使用的默认编码是gb2312 // MailMessage mail = new MailMessage(); // //发件人 // mail.From = new MailAddress("test@mysite", "测试账号"); ////收件人 // mail.To.Add(new MailAddress("nll@mysite")); // //主题 // mail.Subject = "成绩单"; // //内容 // mail.Body = "语文:80,数学:50"; // //发送html格式的邮件 // //AlternateView.CreateAlternateViewFromString("", null, "text/html"); // //mail.AlternateViews.Add(new AlternateView()); // //附件 // mail.Attachments.Add(new Attachment(@"c:\about_banner.png")); // //这是发送邮件服务器的地址和端口号 // using (SmtpClient sc = new SmtpClient("127.0.0.1", 25)) // { // //设置发送邮件的账号和密码 ,必须和发件人的账号一致 // sc.Credentials = new NetworkCredential("test", "test"); // sc.Send(mail); // }