none
发送邮件时,为什么不能发送大的附件 RRS feed

  • 问题

  • 发送邮件时,为什么不能大的附件
    小的附件代码可以通过,但是大的附件(约10M),就报错
    以下是邮件代码:
    System.Net.Mail.SmtpClient client = new SmtpClient();
    client.Host = "smtp.sina.com.cn";
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("taotetmp@sina.com", "123456");
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    //创建mailMessage对象 
    System.Net.Mail.MailMessage message = new MailMessage("taotetmp@sina.com", "taotetmp@sina.com");
    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);
    以下是报错信息:
    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 50
       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

    http://blog.sina.com.cn/taotesea
    2011年9月5日 8:19

答案

全部回复