using System;
using System.Net;
using System.Net.Mail;
using System.Text;
public class MailClient
{
private SmtpClient client;
private string errorMessage = "";
private string fromEmail = "XXX@sina.com";
private string password = "********";
private string smtpHost = "smtp.sina.com";
private string username = "XXX@sina.com";
public MailClient()
{
this.client = new SmtpClient(this.smtpHost);
this.client.DeliveryMethod = SmtpDeliveryMethod.Network;
this.client.UseDefaultCredentials = false;
this.client.Credentials = new NetworkCredential(this.username, this.password);
}
public bool Send(string toEmail, string subject, string body, bool isBodyHtml)
{
MailMessage message = new MailMessage();
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
message.From = new MailAddress(this.fromEmail);
message.To.Add(toEmail);
message.Body = body;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = isBodyHtml;
try
{
this.client.Send(message);
return true;
}
catch (Exception exception)
{
this.errorMessage = exception.Message;
return false;
}
}
public string ErrorMessage
{
get
{
return this.errorMessage;
}
}
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
if (mc.Send("XXX@163.com", "title", "<a href='#'>nihao</a>", true))
Response.Write("good");
else
Response.Write("bad");
代码亲测,绝对能用。邮箱支持sina ,qq,163的好像不支持。