用163邮箱发送邮件
<pre name="code" class="csharp">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;
using System.Net.Mail;
namespace smtp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("user");
//利用MailMessage.To.Add方法增加要发送的邮件地址
mail.To.Add(textBox1 .Text .Trim ());
mail.Subject = textBox2.Text.Trim();
mail.Body = richTextBox1.Text;
mail.IsBodyHtml = false;
mail.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.163.com";
//要输入邮箱用户名与密码
smtp.Credentials = new NetworkCredential("user","password");
try
{
smtp.Send(mail);
MessageBox.Show("发送成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message );
}
}
}
}