用这个类试试
public class MyEmail
{
private string from;
private string to;
private string subject;
private string body;
public MyEmail(string from, string to, string subject, string body)
{
this.from = from;
this.to = to;
this.subject = subject;
this.body = body; }
public string From
{
get { return from; }
set { from = value; }
}
public string To
{
get { return to; }
set { to = value; } }
public string Subject
{
get { return subject; }
set { subject = value; } }
public string Body
{
get { return body; }
set { body = value; }
}
public bool Send()
{ try
{
//MailMessage represents the e-mail being sent
using (MailMessage message = new MailMessage(From, To, Subject, Body))
{ SmtpClient smtp = new SmtpClient("smtp.sina.com.cn"); smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "pwd");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//Send delivers the message to the mail server
smtp.Send(message);
return true;
}
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has oCCured: " + ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
}
public class MyEmail
{
private string from;
private string to;
private string subject;
private string body;
public MyEmail(string from, string to, string subject, string body)
{
this.from = from;
this.to = to;
this.subject = subject;
this.body = body; }
public string From
{
get { return from; }
set { from = value; }
}
public string To
{
get { return to; }
set { to = value; } }
public string Subject
{
get { return subject; }
set { subject = value; } }
public string Body
{
get { return body; }
set { body = value; }
}
public bool Send()
{ try
{
//MailMessage represents the e-mail being sent
using (MailMessage message = new MailMessage(From, To, Subject, Body))
{ SmtpClient smtp = new SmtpClient("smtp.sina.com.cn"); smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "pwd");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//Send delivers the message to the mail server
smtp.Send(message);
return true;
}
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException has oCCured: " + ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货