如何使用C#Windows应用程序通过电子邮件发送大文件 [英] How to email large files using c# windows application

查看:112
本文介绍了如何使用C#Windows应用程序通过电子邮件发送大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows应用程序,需要在其中通过电子邮件发送一些文件作为附件.

I'm developing an windows application in which i need to send some files as attachment through email.

public string SendMail(string mFrom,
        string mPass,
        string mTo,
        string mSub,
        string mMsg,
        string mFile,
        bool isDel)
    {
        string sql = "";
        try
        {
            System.Net.Mail.MailAddress mailfrom = new System.Net.Mail.MailAddress(mFrom);
            System.Net.Mail.MailAddress mailto = new System.Net.Mail.MailAddress(mTo);
            System.Net.Mail.MailMessage newmsg = new System.Net.Mail.MailMessage(mailfrom, mailto);
            newmsg.IsBodyHtml = false;
            if (mFile.Length > 2
                && File.Exists(mFile))
            {
                System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(mFile);
                newmsg.Attachments.Add(att);
            }
            newmsg.Subject = mSub;
            newmsg.Body = mMsg;
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential(mFrom, mPass);
            smtp.EnableSsl = true;
            smtp.Send(newmsg);
            newmsg.Dispose();
            GC.Collect();
            sql = "OK";
            if (isDel
                && File.Exists(mFile))
            {
                File.Delete(mFile);
            }
        }
        catch (Exception ex)
        {
            sql = ex.Message;
        }
        return sql;
    }

此代码适用于小文件.但是我需要发送最大1-2 GB的大文件. 为此,该怎么办.

This code works fine for small files.But i need to send large files up to 1-2 GB. For that what to do.

推荐答案

您不能使用电子邮件来获取这些文件,这与您的代码无关.

You cannot use e-mail to get these files across and this has nothing to do with your code.

我认为没有 ANY 提供商会支持发送该大小的文件,更不用说接收它们了.甚至G-Mail也有25 Mb的限制,这已经相当大了.

I don't think there is ANY provider out there who will support sending files of that size let alone receiving them. Even G-Mail has a limit of 25 Mb which is quite large already.

电子邮件不是执行此操作的适当渠道.

E-Mail is not the proper channel to do this.

因此问题不会出在您的代码中,提供程序将限制附件的大小,并在您向他们提供较大文件时拒绝附件.您将在FROM地址中收到一封电子邮件,指出该文件太大,并且电子邮件没有通过.

So the problem will not be in your code, the provider will limit the size of the attachment and just refuse them when you present them with a larger file. You will get an e-mail back at your FROM address stating that the file is too large and your e-mail did not get across.

要以最简单的形式执行此操作,请查看FTP.

For doing this in the simplest form probably look at FTP.

这篇关于如何使用C#Windows应用程序通过电子邮件发送大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆