C#郵件驗證(用指定郵箱給另外的郵箱發郵件)
阿新 • • 發佈:2019-02-09
private void button1_Click(object sender, EventArgs e)
{
//發信人和收信人以及內容
MailMessage msg = new MailMessage();
msg.Body = this.richTextBox1.Text;
msg.Subject = this.textBox2.Text;
msg.From = new MailAddress("[email protected]");
msg.To.Add(this.textBox1.Text);//傳送到哪兒
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(textBox3.Text));
//伺服器
SmtpClient client = new SmtpClient();
client.Host = "smtp.163.com";//發件方伺服器地址
client.Port = 25;//可以省略 埠
//證書的設定
NetworkCredential credential = new NetworkCredential();
credential.UserName = "anxin591025";
credential.Password = "";
client.Credentials = credential;
client.Send(msg);
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
//op.ShowDialog();
if(System.Windows.Forms.DialogResult.OK==op.ShowDialog())
textBox3.Text = op.FileName;
}
{
//發信人和收信人以及內容
MailMessage msg = new MailMessage();
msg.Body = this.richTextBox1.Text;
msg.Subject = this.textBox2.Text;
msg.From = new MailAddress("[email protected]");
msg.To.Add(this.textBox1.Text);//傳送到哪兒
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(textBox3.Text));
//伺服器
SmtpClient client = new SmtpClient();
client.Host = "smtp.163.com";//發件方伺服器地址
client.Port = 25;//可以省略 埠
//證書的設定
NetworkCredential credential = new NetworkCredential();
credential.UserName = "anxin591025";
credential.Password = "";
client.Credentials = credential;
client.Send(msg);
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
//op.ShowDialog();
if(System.Windows.Forms.DialogResult.OK==op.ShowDialog())
textBox3.Text = op.FileName;
}