📄 getattachmentfilename.htm
字号:
<font color="#ffffff"> </font><font color="#7f0055"><b>if </b></font><font color="#000000">(</font><font color="#000000">folder == </font><font color="#7f0055"><b>null</b></font><font color="#000000">) {</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">"Folder " </font><font color="#000000">+ server.getFile</font><font color="#000000">() </font><font color="#000000">+ </font><font color="#2a00ff">" not found."</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">System.exit</font><font color="#000000">(</font><font color="#990000">1</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#ffffff"> </font><font color="#000000">folder.open</font><font color="#000000">(</font><font color="#000000">Folder.READ_ONLY</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"></font><br/><font color="#ffffff"> </font><font color="#000000">Message</font><font color="#000000">[] </font><font color="#000000">messages = folder.getMessages</font><font color="#000000">()</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#7f0055"><b>for </b></font><font color="#000000">(</font><font color="#7f0055"><b>int </b></font><font color="#000000">i = </font><font color="#990000">0</font><font color="#000000">; i < messages.length; i++</font><font color="#000000">) {</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#000000">messages</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.getSize</font><font color="#000000">() </font><font color="#000000">+ </font><font color="#2a00ff">" bytes long."</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#000000">messages</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.getLineCount</font><font color="#000000">() </font><font color="#000000">+ </font><font color="#2a00ff">" lines."</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">String disposition = messages</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.getDisposition</font><font color="#000000">()</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#7f0055"><b>if </b></font><font color="#000000">(</font><font color="#000000">disposition == </font><font color="#7f0055"><b>null</b></font><font color="#000000">){</font><br/><font color="#ffffff"> </font><font color="#000000">; </font><font color="#3f7f5f">// do nothing</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><font color="#7f0055"><b>else if </b></font><font color="#000000">(</font><font color="#000000">disposition.equals</font><font color="#000000">(</font><font color="#000000">Part.INLINE</font><font color="#000000">)) {</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">"This part should be displayed inline"</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">} </font><font color="#7f0055"><b>else if </b></font><font color="#000000">(</font><font color="#000000">disposition.equals</font><font color="#000000">(</font><font color="#000000">Part.ATTACHMENT</font><font color="#000000">)) {</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">"This part is an attachment"</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">String fileName = messages</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.getFileName</font><font color="#000000">()</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">"The file name of this attachment is " </font><font color="#000000">+ fileName</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#ffffff"> </font><font color="#000000">String description = messages</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.getDescription</font><font color="#000000">()</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#7f0055"><b>if </b></font><font color="#000000">(</font><font color="#000000">description != </font><font color="#7f0055"><b>null</b></font><font color="#000000">) {</font><br/><font color="#ffffff"> </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">"The description of this message is " </font><font color="#000000">+ description</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#ffffff"> </font><font color="#000000">folder.close</font><font color="#000000">(</font><font color="#7f0055"><b>false</b></font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#000000">}</font><br/><font color="#ffffff"></font><br/><font color="#7f0055"><b>class </b></font><font color="#000000">MailAuthenticator </font><font color="#7f0055"><b>extends </b></font><font color="#000000">Authenticator </font><font color="#000000">{</font><br/><font color="#ffffff"></font><br/><font color="#ffffff"> </font><font color="#7f0055"><b>public </b></font><font color="#000000">MailAuthenticator</font><font color="#000000">() {</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#ffffff"></font><br/><font color="#ffffff"> </font><font color="#7f0055"><b>public </b></font><font color="#000000">PasswordAuthentication getPasswordAuthentication</font><font color="#000000">() {</font><br/><font color="#ffffff"> </font><font color="#7f0055"><b>return new </b></font><font color="#000000">PasswordAuthentication</font><font color="#000000">(</font><font color="#2a00ff">"username"</font><font color="#000000">, </font><font color="#2a00ff">"password"</font><font color="#000000">)</font><font color="#000000">;</font><br/><font color="#ffffff"> </font><font color="#000000">}</font><br/><font color="#000000">}</font><br/><font color="#ffffff"></font><br/><font color="#ffffff"></font><br/><font color="#ffffff"> </font><br/><font color="#ffffff"> </font></code></div> </td> <!-- end source code --> </tr></table></td></tr><tr><td><A href="http://www.java2s.com/Code/JavaDownload/JavaMailGetAttachmentFileName.zip"><IMG border=0 width=32 heigh=32 src="http://www.java2s.com/style/download.png">JavaMailGetAttachmentFileName.zip( 2,322 k)</a></td></tr><tr><td class=relatedExample>Related examples in the same category</td></tr></table><table cellpadding=0 cellspacing=0 width=800 border=0><tr class=even><td>1. </td><td align=left><A href="http://www.java2s.com/Code/Java/Email/HowtousetheFileDataSourcetosendafileviamail.htm">How to use the FileDataSource to send a file via mail</a></td><td width=32></td><td width=200 align=right></td></tr></table><TABLE border=0><TR><TD height=10></TD></TR></TABLE><script type="text/javascript"><!--google_ad_client = "pub-1130008796007602"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; google_ad_channel = ""; google_color_border = "ffffff"; google_color_bg = "ffffff"; google_color_link = "003399"; google_color_text = "000000"; google_color_url = "75a3ed"; // --> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </td></tr></table></td></tr></table> <center><TABLE border=0> <TR align=left> <TD> <A href="http://www.java2s.com">w__w__w_.___j_a__v__a__2___s_.__c__o__m</A> | <A href=http://www.java2s.com/html/contact.htm>Contact Us</A> </Td> </TR> <TR align=left> <TD class=Templatetext>Copyright 2003 - 08 Demo Source and Support. All rights reserved.</TD> </TR> <TR align=left> <TD>All other trademarks are property of their respective owners.</TD> </TR></TABLE></center></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -