我用c#2.0写了一个邮件发送小程序,
在使用本地IIS服务设置是没有问题的,可以发送。
可是使用外网却不可以进行发送邮件,
我用我其他人用Delphi进行外网SMTP服务器测试是可以的,
这就说明还是我原程序中出现了问题,请问是什么原因?
代码如下:
           mail = new MailMessage();
           mailAddress = new MailAddress(sSender, sSenderName);
           mail.From = mailAddress;
           mail.Subject = sSubject;
           mail.Body = sContent;           //创建SmtpClient 
           SmtpClient SmtpMail = new SmtpClient(sSmtpServer, iPort);
           SmtpMail.Credentials = new NetworkCredential(sUserName, sPassword);
           SmtpMail.Send(mail);sSender,sSenderName,sSmtpServer,iPort,sUserName,sPassword
各参数都没有问题,因为我用同样的参数用Delphi程序测试可以发送,用C#上面的代码测试总是出现“Failure sending mail.”的错误
请大家帮忙解决!

解决方案 »

  1.   

    问题补充:
    我用try捕捉异常为以下信息:
    System.Net.Mail.SmtpException: Failure sending mail. ---> System.FormatException: Invalid length for a Base-64 char array.
       at System.Convert.FromBase64String(String s)
       at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
       at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie)
       at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       --- End of inner exception stack trace ---
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at Test.MainForm.InnerExceptions() in c:\Documents and Settings\Administrator\My Documents\SharpDevelop Projects\Test\MainForm.cs:line 93System.FormatException: Invalid length for a Base-64 char array.
       at System.Convert.FromBase64String(String s)
       at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
       at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie)
       at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
      

  2.   

    晕,邮件服务器.SMTP这方面的东西不是太懂.不过可以关注一下你的贴子!
      

  3.   

    look
    http://www.systemnetmail.com/
      

  4.   

    line 93System.FormatException: Invalid length for a Base-64 char array.
      

  5.   

    谢谢各位的参与,我已经解决了这个问题,因为少了个发送方式!
    //使用IIS发送邮件
     SmtpMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;