using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;
namespace 电子邮件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.Subject = this.textBox2.Text;
msg.Body = this.textBox3.Text;
msg.From = new MailAddress("zhenghs1013@qq.com");QQ邮箱
msg.To.Add(this.textBox1.Text);//获取收件人的地址
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.qq.com";
client.Port = 25;
NetworkCredential credetial = new NetworkCredential();
credetial.UserName = "zhenghs1013@qq.com"; QQ邮箱
credetial.Password = "QQ密码";
client.Credentials = credetial;
Attachment att=new Attachment(this.textBox4.Text);
msg.Attachments.Add(att);
client.Send(msg);
MessageBox.Show("发送成功!","提示");
}
private void button2_Click(object sender, EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox4.Text = this.openFileDialog1.FileName;
}
}
}
}