在ASP.Net中下载电子邮件附件 [英] Download email attachment in ASP.Net

查看:143
本文介绍了在ASP.Net中下载电子邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Web的电子邮件客户端,该客户端连接到pop3.client.我收到了电子邮件以及所有内容,并且找到了直接下载文件的代码,而无需询问用户.

这使电子邮件的加载速度变慢,因为它必须先下载所有文件,然后才能将信息保存到数据库中并在页面上显示出来.

有没有一种方法可以使用保存对话框来下载每个文件?请记住,文件类型是未知的,因为它是电子邮件的一部分.我已经研究过response.transmitfile(),但是不会这样做,因为我不知道文件的路径(它在邮件对象中).

我还看到了应该执行此操作的reponse.binarywrite和response.outputstream,我只是不知道该怎么做,我可以找到的所有示例代码都是基于将文件保存在其中的假设.一个app_folder或动态生成的.

我认为,如果我可以获取文件字节并将其存储到数组中,则可以执行此操作,但是再次,我只是不知道如何操作.




原始问题:如何使用保存对话框从asp.net中的pop3服务器下载电子邮件附件?

I have a web-base email client that connects to a pop3.client. I get the emails and everything and I''ve found code to download the files directly without asking the user.

This makes the email loading slower because it has to download all files before it can save the info on the database an show it on the page.

Is there a way I could use a save dialog to download each file? Keep in mind that the type of file is unknown because it comes as part of the email message. I''ve researched about the response.transmitfile() but that won''t do because I don''t know the path to the file (it is in the mail object).

I''ve also seen the reponse.binarywrite and response.outputstream which should do this, I just don''t know how to do it, and all the sample codes I can find are based on the assumption that the file is saved in an app_folder or dynamically generated.

I think if I can get the filebytes and store them to an array I could do this but again, I just don''t know how.




Original question: How can I use a save dialog to download an email attachment from a pop3 server in asp.net?

推荐答案

我正确理解:您正在使用pop3协议下载带有附件的电子邮件,并将所有内容存储在数据库中.
附件还在数据库中还是什么?

要强制浏览器显示保存"对话框,请使用以下内容:
Did I understand correctly: you''re downloading an email with attachments using pop3 protocol and storing everything in your database.
Are attachments also in the database or what?

To force browser to display ''Save'' dialog use something like this:
private void SendResponse(string downloadName, byte[] responseBytes)
{
	System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
	response.Clear();
	response.AddHeader("Content-Type", "binary/octet-stream");
    	response.AddHeader("Content-Disposition", "attachment; filename=" + 
            downloadName + "; size=" + responseBytes.Length.ToString());
	response.BinaryWrite(responseBytes);
	response.Flush();
	response.End();
}



在此示例中,文件内容位于byte []中,但可以轻松地对其进行修改以使用Streams.



In this example file content is in byte[], but it can easily be modified to use Streams.


这篇关于在ASP.Net中下载电子邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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