阅读邮件附件 [英] Read Mail Attachement

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

问题描述

大家好,我已经创建了一个从服务器读取电子邮件的程序,因此当我尝试提取attachemetn文件并将其转换为原始base64时,它不起作用
有人可以帮我吗

Hi everybody i have create a program to read an E_mail from Server so when i attempt to extract the attachemetn file and convert it into original base64 it doesn''t work
Can someon help me please

推荐答案

不需要将其转换为原始base64"-所谓的附件"是通常以base64编码的电子邮件部分在多部分消息中已经存在(或者对于文本部分可能只是纯文本).用纯文本编辑器打开任何邮件块,然后自己查看.

请参阅以下CodeProject文章: http://www.codeproject.com/search.aspx? doctypeid = 1& q = pop3 + mail +"C%23" [ ^ ].

即使您不使用POP3,也可以找到解决方案的其余部分,这是您缺少的解决方案:如何解析多部分邮件消息并提取部分.这样,您可以提取附件".

而且您的不起作用"也无法提供信息-如果您仍然无法解决它,请使用上方的改善问题"显示代码.

—SA
There is no need to "convert it into original base64" — so called "attachment" is an e-mail part usually encoded in base64 already (or it could be just plain text, for text parts), in a multi-part messages. Open any mail block with a plain text editor and see by yourself.

Please see these CodeProject articles: http://www.codeproject.com/search.aspx?doctypeid=1&q=pop3+mail+"C%23"[^].

Even if you don''t use POP3, you will find the rest of the solution, the one you are missing: how to parse the multipart mail message and extract parts. This way, you can extract "attachments".

And your "does not work" is not informative — if you still cannot resolve it, show your code using "Improve question" above.

—SA


对不起,我已将部分内容发送给您,所以在这里是
sorry I''ve forgeot tsend to you the part of so here it is
if (blocMail.IndexOf("Content-Disposition: attachment") != -1)
                   {
                       int debut = blocMail.IndexOf("Content-Disposition: attachment");
                       int longeur = blocMail.Length;
                       string pieceJointe = blocMail.Substring(debut);
                       string[] pj = pieceJointe.Split('\n');
                       string[] nomPj = pj[1].Split('"');
                       string nooomPieceJointe = nomPj[1].ToString();
                       int debutPj = pieceJointe.IndexOf(nooomPieceJointe)+nooomPieceJointe.Length+1;

                       int fin = pieceJointe.IndexOf("\n--");
                       string pieceJointee = pieceJointe.Substring(fin);
                       //int debSub = (pieceJointe.Length - debutPj);
                       int finSub = (pieceJointe.Length - fin);
                       int longSub= pieceJointe.Length-(debutPj+finSub );
                       string contenuPieceJointe = pieceJointe.Substring(debutPj,longSub);

                       //string content = blocMail.Substring(debut, fin);
                       //MessageBox.Show(contenuPieceJointe);


                       contenuPieceJointe = ConversionBase64("\n"+contenuPieceJointe.Trim()+"\n");
                       StreamWriter swPj = new StreamWriter(repertoireMail + "\\" + nooomPieceJointe, false);
                       swPj.WriteLine(contenuPieceJointe);
                       swPj.Close();
                   }


这篇关于阅读邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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