本帖最后由 taotesea 于 2011-09-05 16:33:27 编辑

解决方案 »

  1.   

    从异常看是数组越界了
    System.IndexOutOfRangeException: Index was outside the bounds of the array.
    估计是字节流缓冲区满了
    楼主不妨试试大附件拆分成若干个小附件,分别发送
    然后在接收端拼起来
      

  2.   

    数据量过大肯定会有一个TimeOut 问题,你把TimeOut 时间设长一点.等待文件传送完毕.我刚刚试了一下.可以.因为上传10M的文件不是那么快的.而默认的TimeOut 会判断传送失败引发异常.
      

  3.   

    我刚刚用你的代码,我把     client.Timeout = 30000000; 发了一个11M的文件发送成功了. 大概等了十几分钟.
    LZ可以试一下.
      

  4.   

    还是报错,以下是加入了TimeOut
    //创建smtpclient对象
    System.Net.Mail.SmtpClient client = new SmtpClient();
    client.Host = "smtp.sina.com.cn";
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("[email protected]", "123456");
    client.Timeout=100000;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    //创建mailMessage对象 
    System.Net.Mail.MailMessage message = new MailMessage("[email protected]", "[email protected]");
    message.Subject = "Test";
    //正文默认格式为html
    message.Body = "Test";
    message.IsBodyHtml = true;
    message.BodyEncoding = System.Text.Encoding.UTF8;
    Attachment data = new Attachment("C:\\aa.7z", System.Net.Mime.MediaTypeNames.Application.Octet);
    message.Attachments.Add(data);
    client.Send(message);
    Close();
      

  5.   

    还是报错,代码如下:
    //创建smtpclient对象
    System.Net.Mail.SmtpClient client = new SmtpClient();
    client.Host = "smtp.sina.com.cn";
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("[email protected]", "123456");
    client.Timeout = 30000000;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    //创建mailMessage对象 
    System.Net.Mail.MailMessage message = new MailMessage("[email protected]", "[email protected]");
    message.Subject = "Test";
    //正文默认格式为html
    message.Body = "Test";
    message.IsBodyHtml = true;
    message.BodyEncoding = System.Text.Encoding.UTF8;
    Attachment data = new Attachment("C:\\aa.7z", System.Net.Mime.MediaTypeNames.Application.Octet);
    message.Attachments.Add(data);
    client.Send(message);
    Close();
    报错如下:
    System.Net.Mail.SmtpException: Failure sending mail. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at System.Net.Base64Stream.EncodeBytes(Byte[] buffer, Int32 offset, Int32 count, Boolean dontDeferFinalBytes, Boolean shouldAppendSpaceToCRLF)
       at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Mime.MimePart.Send(BaseWriter writer)
       at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer)
       at System.Net.Mail.Message.Send(BaseWriter writer, Boolean sendEnvelope)
       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.Button1_Click(Object sender, EventArgs e) in d:\SharpDevelop\MyProjects\CSharp\Test\Test\MainForm.cs:line 51
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Test.Program.Main(String[] args) in d:\SharpDevelop\MyProjects\CSharp\Test\Test\Program.cs:line 26
      

  6.   

    我用的是163.com 网易的邮箱,发送到我的qq.com 邮箱上的.测试是成功的.你可以弄个163试试.也许你的邮件服务器不支持传送这么大的文件.