最近公司让研究一下发送邮件..试过VB C#感觉还是C#较比稳定些.下面将代码共享一下 2.0
public
class
SendMail

...
{
private string _host;
public string Host

...{

get ...{ return _host; }

set ...{ _host = value; }
}
private int _port;
public int Port

...{

get ...{ return _port; }

set ...{ _port = value; }
}
private string _smtpUsername;
public string SmtpUsername

...{

get ...{ return _smtpUsername; }

set ...{ _smtpUsername = value; }
}
private string _smtpPassword;
public string SmtpPassword

...{

get ...{ return _smtpPassword; }

set ...{ _smtpPassword = value; }
}
public void Send(string from, string to, string subject, string body, string[] cc, string[] bcc)

...{
// Create mail message
MailMessage message = new MailMessage(from, to, subject, body);
message.BodyEncoding = Encoding.GetEncoding(936);
if (cc != null && cc.Length > 0)

...{
foreach (string ccAddress in cc)

...{
message.CC.Add(new MailAddress(ccAddress));
}
}
if (bcc != null && bcc.Length > 0)

...{
foreach (string bccAddress in bcc)

...{
message.Bcc.Add(new MailAddress(bccAddress));
}
}
// Send email
SmtpClient client = new SmtpClient(this._host, 25);
if (!String.IsNullOrEmpty(this._smtpUsername) && !String.IsNullOrEmpty(this._smtpPassword))

...{
client.Credentials = new NetworkCredential(this._smtpUsername, this._smtpPassword);
}
client.EnableSsl = false;
client.Send(message);
}

调用:
try

...{
SendMail mail = new SendMail();
mail.Host = this.txt_MailServer.Text;//服务器smtp地址
mail.SmtpUsername = this.txt_UserName.Text;//登陆用户名
mail.SmtpPassword = this.txt_Pass.Text;//登录密码
mail.Send(this.txt_MailAdder.Text, this.txt_toMail.Text, this.txt_title.Text, this.txt_body.Text, null, null);//发件人地址,收件人地址,标题,内容,其他,其他
}
catch (Exception ex)

...{
//可以捕获异常
}
