.NET 2.0中发送邮件的问题

写了一个发送邮件的类:

 public class SendMail
 {
  private static string m_UserName;
  private static string m_Password;
  private static string m_HostName;

  static string returnMSG = "";

  public static void NewMailServer(string user, string pwd, string host){
   m_UserName = user;
   m_Password = pwd;
   m_HostName = host;
  }

  public static string Send(string from, string sentto, string cc, string
bc, string subject, string body)
  {
   try
   {
    MailMessage message = new MailMessage(new MailAddress(from, "Rui " +
(char)0xD8 + " Chen", System.Text.Encoding.UTF8), new MailAddress(sentto));

    message.Subject = subject;
    message.Body = body;
    message.IsBodyHtml = true;

    SmtpClient mailclient = new SmtpClient();

    mailclient.Host = m_HostName;
    mailclient.Credentials = new NetworkCredential(m_UserName, m_Password);
    mailclient.UseDefaultCredentials = false;
    mailclient.Timeout = 100000;
    mailclient.DeliveryMethod = SmtpDeliveryMethod.Network;

    mailclient.Send(message);
    return returnMSG;
   }
   catch (System.Net.Mail.SmtpException sEx)
   {
    return sEx.StatusCode.ToString() + " : " + sEx.Source + sEx.ToString();
   }
  }

  private SendMail()
  {

  }
 }

但是在调用的时候出现错误:

MailboxNameNotAllowed : System System.Net.Mail.SmtpException: Mailbox name
not allowed. The server response was: You are not authorized to send mail as
 >, authentication is required at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String
response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[]
command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress
from, MailAddressCollection recipients, SmtpFailedRecipientException&
exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at
Merlion.Web.Mail.SendMail.Send(String from, String sentto, String cc, String
bc, String subject, String body) in c:/Documents and Settings/陈锐/My
Documents/Visual Studio 2005/WebSites/WebSite3/App_Code/SendMail.cs:line 53

8直到是什么原因,搞了一下午,郁闷。不行干脆用Socket写一个自己的SMTP实现算了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值