<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FEmail%2FEmail_Attachment</id>
		<title>Java Tutorial/Email/Email Attachment - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FEmail%2FEmail_Attachment"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Email/Email_Attachment&amp;action=history"/>
		<updated>2026-04-21T20:07:32Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Email/Email_Attachment&amp;diff=3371&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Email/Email_Attachment&amp;diff=3371&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Email/Email_Attachment&amp;diff=3372&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Email/Email_Attachment&amp;diff=3372&amp;oldid=prev"/>
				<updated>2010-05-31T15:23:15Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Get Attachment File Name ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
import javax.mail.Authenticator;&lt;br /&gt;
import javax.mail.Folder;&lt;br /&gt;
import javax.mail.Message;&lt;br /&gt;
import javax.mail.Part;&lt;br /&gt;
import javax.mail.PasswordAuthentication;&lt;br /&gt;
import javax.mail.Session;&lt;br /&gt;
import javax.mail.URLName;&lt;br /&gt;
import javax.mail.internet.InternetAddress;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    URLName server = new URLName(&amp;quot;protocol://username@host/foldername&amp;quot;);&lt;br /&gt;
    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());&lt;br /&gt;
    Folder folder = session.getFolder(server);&lt;br /&gt;
    if (folder == null) {&lt;br /&gt;
      System.out.println(&amp;quot;Folder &amp;quot; + server.getFile() + &amp;quot; not found.&amp;quot;);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    folder.open(Folder.READ_ONLY);&lt;br /&gt;
    Message[] messages = folder.getMessages();&lt;br /&gt;
    for (int i = 0; i &amp;lt; messages.length; i++) {&lt;br /&gt;
      System.out.println(messages[i].getSize() + &amp;quot; bytes long.&amp;quot;);&lt;br /&gt;
      System.out.println(messages[i].getLineCount() + &amp;quot; lines.&amp;quot;);&lt;br /&gt;
      String disposition = messages[i].getDisposition();&lt;br /&gt;
      if (disposition == null){&lt;br /&gt;
        ; // do nothing&lt;br /&gt;
      }else if (disposition.equals(Part.INLINE)) {&lt;br /&gt;
        System.out.println(&amp;quot;This part should be displayed inline&amp;quot;);&lt;br /&gt;
      } else if (disposition.equals(Part.ATTACHMENT)) {&lt;br /&gt;
        System.out.println(&amp;quot;This part is an attachment&amp;quot;);&lt;br /&gt;
        String fileName = messages[i].getFileName();&lt;br /&gt;
        System.out.println(&amp;quot;The file name of this attachment is &amp;quot; + fileName);&lt;br /&gt;
      }&lt;br /&gt;
      String description = messages[i].getDescription();&lt;br /&gt;
      if (description != null) {&lt;br /&gt;
        System.out.println(&amp;quot;The description of this message is &amp;quot; + description);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    folder.close(false);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class MailAuthenticator extends Authenticator {&lt;br /&gt;
  public MailAuthenticator() {&lt;br /&gt;
  }&lt;br /&gt;
  public PasswordAuthentication getPasswordAuthentication() {&lt;br /&gt;
    return new PasswordAuthentication(&amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  How to use the FileDataSource to send a file via mail ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * @(#)sendfile.java  1.11 03/06/19&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright 1996-2003 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * &lt;br /&gt;
 * - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *   notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * &lt;br /&gt;
 * - Redistribution in binary form must reproduce the above copyright&lt;br /&gt;
 *   notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *   documentation and/or other materials provided with the distribution.&lt;br /&gt;
 * &lt;br /&gt;
 * Neither the name of Sun Microsystems, Inc. or the names of contributors&lt;br /&gt;
 * may be used to endorse or promote products derived from this software&lt;br /&gt;
 * without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,&lt;br /&gt;
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A&lt;br /&gt;
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND&lt;br /&gt;
 * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES&lt;br /&gt;
 * SUFFERED BY LICENSEE AS A RESULT OF  OR RELATING TO USE, MODIFICATION&lt;br /&gt;
 * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL&lt;br /&gt;
 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR&lt;br /&gt;
 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE&lt;br /&gt;
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,&lt;br /&gt;
 * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS&lt;br /&gt;
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 * &lt;br /&gt;
 * You acknowledge that Software is not designed, licensed or intended&lt;br /&gt;
 * for use in the design, construction, operation or maintenance of any&lt;br /&gt;
 * nuclear facility.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import javax.mail.*;&lt;br /&gt;
import javax.mail.internet.*;&lt;br /&gt;
import javax.activation.*;&lt;br /&gt;
/**&lt;br /&gt;
 * sendfile will create a multipart message with the second&lt;br /&gt;
 * block of the message being the given file.&amp;lt;P&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * This demonstrates how to use the FileDataSource to send&lt;br /&gt;
 * a file via mail.&amp;lt;P&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * usage: &amp;lt;code&amp;gt;java sendfile &amp;lt;i&amp;gt;to from smtp file true|false&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
 * where &amp;lt;i&amp;gt;to&amp;lt;/i&amp;gt; and &amp;lt;i&amp;gt;from&amp;lt;/i&amp;gt; are the destination and&lt;br /&gt;
 * origin email addresses, respectively, and &amp;lt;i&amp;gt;smtp&amp;lt;/i&amp;gt;&lt;br /&gt;
 * is the hostname of the machine that has smtp server&lt;br /&gt;
 * running.  &amp;lt;i&amp;gt;file&amp;lt;/i&amp;gt; is the file to send. The next parameter&lt;br /&gt;
 * either turns on or turns off debugging during sending.&lt;br /&gt;
 *&lt;br /&gt;
 * @author  Christopher Cotton&lt;br /&gt;
 */&lt;br /&gt;
public class sendfile {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
  if (args.length != 5) {&lt;br /&gt;
      System.out.println(&amp;quot;usage: java sendfile &amp;lt;to&amp;gt; &amp;lt;from&amp;gt; &amp;lt;smtp&amp;gt; &amp;lt;file&amp;gt; true|false&amp;quot;);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
  }&lt;br /&gt;
  String to = args[0];&lt;br /&gt;
  String from = args[1];&lt;br /&gt;
  String host = args[2];&lt;br /&gt;
  String filename = args[3];&lt;br /&gt;
  boolean debug = Boolean.valueOf(args[4]).booleanValue();&lt;br /&gt;
  String msgText1 = &amp;quot;Sending a file.\n&amp;quot;;&lt;br /&gt;
  String subject = &amp;quot;Sending a file&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  // create some properties and get the default Session&lt;br /&gt;
  Properties props = System.getProperties();&lt;br /&gt;
  props.put(&amp;quot;mail.smtp.host&amp;quot;, host);&lt;br /&gt;
  &lt;br /&gt;
  Session session = Session.getInstance(props, null);&lt;br /&gt;
  session.setDebug(debug);&lt;br /&gt;
  &lt;br /&gt;
  try {&lt;br /&gt;
      // create a message&lt;br /&gt;
      MimeMessage msg = new MimeMessage(session);&lt;br /&gt;
      msg.setFrom(new InternetAddress(from));&lt;br /&gt;
      InternetAddress[] address = {new InternetAddress(to)};&lt;br /&gt;
      msg.setRecipients(Message.RecipientType.TO, address);&lt;br /&gt;
      msg.setSubject(subject);&lt;br /&gt;
      // create and fill the first message part&lt;br /&gt;
      MimeBodyPart mbp1 = new MimeBodyPart();&lt;br /&gt;
      mbp1.setText(msgText1);&lt;br /&gt;
      // create the second message part&lt;br /&gt;
      MimeBodyPart mbp2 = new MimeBodyPart();&lt;br /&gt;
            // attach the file to the message&lt;br /&gt;
        FileDataSource fds = new FileDataSource(filename);&lt;br /&gt;
      mbp2.setDataHandler(new DataHandler(fds));&lt;br /&gt;
      mbp2.setFileName(fds.getName());&lt;br /&gt;
      // create the Multipart and add its parts to it&lt;br /&gt;
      Multipart mp = new MimeMultipart();&lt;br /&gt;
      mp.addBodyPart(mbp1);&lt;br /&gt;
      mp.addBodyPart(mbp2);&lt;br /&gt;
      // add the Multipart to the message&lt;br /&gt;
      msg.setContent(mp);&lt;br /&gt;
      // set the Date: header&lt;br /&gt;
      msg.setSentDate(new Date());&lt;br /&gt;
      &lt;br /&gt;
      // send the message&lt;br /&gt;
      Transport.send(msg);&lt;br /&gt;
      &lt;br /&gt;
  } catch (MessagingException mex) {&lt;br /&gt;
      mex.printStackTrace();&lt;br /&gt;
      Exception ex = null;&lt;br /&gt;
      if ((ex = mex.getNextException()) != null) {&lt;br /&gt;
    ex.printStackTrace();&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>