b'\n_START_ARTICLE_\nJavaMail\n_START_SECTION_\nA JavaMail haszn\xc3\xa1lata\n_START_PARAGRAPH_\n1. Egy JavaMail kliens jellemz\xc5\x91en egy Session objektum l\xc3\xa9trehoz\xc3\xa1s\xc3\xa1val kezd\xc5\x91dik:_NEWLINE_Session session = Session.getInstance(props, authenticator);_NEWLINE_2. A Session objektum getStore() met\xc3\xb3dus\xc3\xa1nak seg\xc3\xadts\xc3\xa9g\xc3\xa9vel kapcsol\xc3\xb3dik az alap\xc3\xa9rtelmezett t\xc3\xa1rol\xc3\xb3hoz, valamint a connect() met\xc3\xb3dus seg\xc3\xadts\xc3\xa9g\xc3\xa9vel hozhatja l\xc3\xa9tre a t\xc3\xa9nyleges kapcsolatot:_NEWLINE_Store store = session.getStore();store.connect();_NEWLINE_3. Amennyiben a kapcsolat sikeresen l\xc3\xa9trej\xc3\xb6tt, a kliens el\xc3\xa9ri az adott t\xc3\xa1rol\xc3\xb3 mapp\xc3\xa1it \xc3\xa9s az azokban l\xc3\xa9v\xc5\x91 leveleket:_NEWLINE_// az INBOX mappa lek\xc3\xa9r\xc3\xa9seFolder inbox = store.getFolder("INBOX");// az INBOX mappa megnyit\xc3\xa1sainbox.open(Folder.READ_WRITE);// az els\xc5\x91 lev\xc3\xa9l lek\xc3\xa9r\xc3\xa9seMessage m = inbox.getMessage(1);// a lev\xc3\xa9l c\xc3\xadm\xc3\xa9nek lek\xc3\xa9r\xc3\xa9seString subject = m.getSubject();// a lev\xc3\xa9l tartalm\xc3\xa1nak lek\xc3\xa9r\xc3\xa9seObject content = m.getContent();_NEWLINE_4. V\xc3\xa9gezet\xc3\xbcl a kliens bez\xc3\xa1rja az \xc3\xb6sszes megnyitott mapp\xc3\xa1t, valamint a t\xc3\xa1rol\xc3\xb3t:_NEWLINE_// INBOX bez\xc3\xa1r\xc3\xa1sainbox.close();// a t\xc3\xa1rol\xc3\xb3 bez\xc3\xa1r\xc3\xa1sastore.close();\n_START_SECTION_\nEgyr\xc3\xa9szes, sima sz\xc3\xb6veges e-mail k\xc3\xbcld\xc3\xa9se\n_START_PARAGRAPH_\nimport java.util.*;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;_NEWLINE_ _NEWLINE_public class TestEmail {_NEWLINE_ _NEWLINE_    public static void main(String[] args) {_NEWLINE_ _NEWLINE_        String to = "sendToMailAddress";_NEWLINE_        String from = "sendFromMailAddress";_NEWLINE_        String host = "smtp.yourisp.net";_NEWLINE_ _NEWLINE_        Properties props = new Properties();_NEWLINE_ _NEWLINE_        // Ha a statikus Transport.send()-et haszn\xc3\xa1ljuk,_NEWLINE_        // meg kell adni melyik hoston kereszt\xc3\xbcl k\xc3\xbcldj\xc3\xbcnk_NEWLINE_        props.put("mail.smtp.host", host);_NEWLINE__NEWLINE_        // Debug bekapcs_NEWLINE_        props.put("mail.debug", "true");_NEWLINE_        Session session = Session.getInstance(props);_NEWLINE_ _NEWLINE_        try {_NEWLINE_            Message msg = new MimeMessage(session);_NEWLINE_ _NEWLINE_            msg.setFrom(new InternetAddress(from));_NEWLINE_            InternetAddress[] address = {new InternetAddress(to)};_NEWLINE_            msg.setRecipients(Message.RecipientType.TO, address);_NEWLINE_            msg.setSubject("sima, sz\xc3\xb6veges email java k\xc3\xb3db\xc3\xb3l");_NEWLINE_            msg.setSentDate(new Date());_NEWLINE_            msg.setText("\xc3\x8dme itt az \xc3\xbczenet,\\n" +_NEWLINE_                        "ez a m\xc3\xa1sodik sora.");_NEWLINE_ _NEWLINE_            Transport.send(msg);_NEWLINE_        }_NEWLINE_        catch (MessagingException mex) {_NEWLINE_            mex.printStackTrace();_NEWLINE_        }_NEWLINE_    }}\n_START_SECTION_\nT\xc3\xb6bbr\xc3\xa9szes e-mail \xc3\xa9s HTML-e-mail k\xc3\xbcld\xc3\xa9se valamint f\xc3\xa1jl csatol\xc3\xa1sa\n_START_PARAGRAPH_\nimport java.util.*;import java.io.*;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;_NEWLINE_ _NEWLINE_public class SendMailUsage {_NEWLINE_ _NEWLINE_    public static void main(String[] args) {_NEWLINE_ _NEWLINE_        String to = "sendToMailAddress";_NEWLINE_        String from = "sendFromMailAddress";_NEWLINE_        String host = "smtpserver.yourisp.net";_NEWLINE_ _NEWLINE_        Properties props = new Properties();_NEWLINE__NEWLINE_        // Ha a statikus Transport.send()-et haszn\xc3\xa1ljuk,_NEWLINE_        // meg kell adni melyik hoston kereszt\xc3\xbcl k\xc3\xbcldj\xc3\xbcnk_NEWLINE_        props.put("mail.smtp.host", host);_NEWLINE__NEWLINE_        // Debug bekapcsol\xc3\xa1sa_NEWLINE_        props.put("mail.debug", "true");_NEWLINE_ _NEWLINE_        Session session = Session.getInstance(props);_NEWLINE_ _NEWLINE_        try {_NEWLINE_            // Transport objektummal t\xc3\xb6rt\xc3\xa9n\xc5\x91 k\xc3\xbcld\xc3\xa9s_NEWLINE_            Transport bus = session.getTransport("smtp");_NEWLINE_ _NEWLINE_            // Csak egyszer csatlakozik_NEWLINE_            // Transport.send() minden k\xc3\xbcld\xc3\xa9s ut\xc3\xa1n kapcsolatot bont_NEWLINE_            // \xc3\x81ltal\xc3\xa1ban, SMTP-hez nem sz\xc3\xbcks\xc3\xa9ges felhaszn\xc3\xa1l\xc3\xb3n\xc3\xa9v \xc3\xa9s jelsz\xc3\xb3_NEWLINE_            bus.connect();_NEWLINE_            //de ha m\xc3\xa9gis, akkor_NEWLINE_            //bus.connect("smtpserver.yourisp.net", "username", "password");_NEWLINE_ _NEWLINE_            Message msg = new MimeMessage(session);_NEWLINE_ _NEWLINE_            msg.setFrom(new InternetAddress(from));_NEWLINE_            InternetAddress[] address = {new InternetAddress(to)};_NEWLINE_            msg.setRecipients(Message.RecipientType.TO, address);_NEWLINE_            msg.setSubject("jav\xc3\xa1s emailk\xc3\xbcld\xc3\xa9s");_NEWLINE_            msg.setSentDate(new Date());_NEWLINE_ _NEWLINE_            // \xc3\x9czenet tartalm\xc3\xa1nak megad\xc3\xa1sa \xc3\xa9s k\xc3\xbcld\xc3\xa9s_NEWLINE_            setTextContent(msg);_NEWLINE_            msg.saveChanges();_NEWLINE_            bus.sendMessage(msg, address);_NEWLINE_ _NEWLINE_            setMultipartContent(msg);_NEWLINE_            msg.saveChanges();_NEWLINE_            bus.sendMessage(msg, address);_NEWLINE_ _NEWLINE_            setFileAsAttachment(msg, "C:/WINDOWS/CLOUD.GIF");_NEWLINE_            msg.saveChanges();_NEWLINE_            bus.sendMessage(msg, address);_NEWLINE_ _NEWLINE_            setHTMLContent(msg);_NEWLINE_            msg.saveChanges();_NEWLINE_            bus.sendMessage(msg, address);_NEWLINE_ _NEWLINE_            bus.close();_NEWLINE__NEWLINE_        }_NEWLINE_        catch (MessagingException mex) {_NEWLINE_            mex.printStackTrace();_NEWLINE_        }_NEWLINE_    }_NEWLINE_ _NEWLINE_    // Egyszer\xc5\xb1, egyr\xc3\xa9szes text/plain email_NEWLINE_    public static void setTextContent(Message msg) throws MessagingException {_NEWLINE_            // \xc3\x9czenet tartalm\xc3\xa1nak be\xc3\xa1ll\xc3\xadt\xc3\xa1sa_NEWLINE_            String mytxt = "\xc3\x8dme itt az email, \\n" +_NEWLINE_                            "ez a m\xc3\xa1sodik sora.";_NEWLINE_            msg.setText(mytxt);_NEWLINE__NEWLINE_            // A form tartalm\xc3\xa1nak megv\xc3\xa1ltoztat\xc3\xa1sa az \xc3\xa1ltalunk defini\xc3\xa1ltra_NEWLINE_            msg.setContent(mytxt, "text/plain");_NEWLINE_ _NEWLINE_    }_NEWLINE_ _NEWLINE_    // Egyszer\xc5\xb1 t\xc3\xb6bbr\xc3\xa9szes e-mail. Mindk\xc3\xa9t t\xc3\xb6rzsr\xc3\xa9sz text/plain._NEWLINE_    public static void setMultipartContent(Message msg) throws MessagingException {_NEWLINE_        // Els\xc5\x91 r\xc3\xa9sz l\xc3\xa9trehoz\xc3\xa1sa \xc3\xa9s kit\xc3\xb6lt\xc3\xa9se_NEWLINE_        MimeBodyPart p1 = new MimeBodyPart();_NEWLINE_        p1.setText("This is part one of a test multipart e-mail.");_NEWLINE_ _NEWLINE_        // M\xc3\xa1sodik r\xc3\xa9sz l\xc3\xa9trehoz\xc3\xa1sa \xc3\xa9s kit\xc3\xb6lt\xc3\xa9se_NEWLINE_        MimeBodyPart p2 = new MimeBodyPart();_NEWLINE_        // A karakterk\xc3\xa9szlet be\xc3\xa1ll\xc3\xadt\xc3\xa1sa_NEWLINE_        p2.setText("Ez a m\xc3\xa1sodik r\xc3\xa9sz", "utf-8");_NEWLINE_ _NEWLINE_        // Multipart l\xc3\xa9trehoz\xc3\xa1sa. A t\xc3\xb6rzsr\xc3\xa9szeket hozz\xc3\xa1adjuk._NEWLINE_        Multipart mp = new MimeMultipart();_NEWLINE_        mp.addBodyPart(p1);_NEWLINE_        mp.addBodyPart(p2);_NEWLINE_ _NEWLINE_        // Be\xc3\xa1ll\xc3\xadtjuk a Multipartot az \xc3\xbczenet tartalm\xc3\xa1nak_NEWLINE_        msg.setContent(mp);_NEWLINE_    }_NEWLINE_ _NEWLINE_    // F\xc3\xa1jl csatol\xc3\xa1sa a JAF FileDataSource haszn\xc3\xa1lat\xc3\xa1val:_NEWLINE_    public static void setFileAsAttachment(Message msg, String filename)throws MessagingException {_NEWLINE_ _NEWLINE_        // Els\xc5\x91 r\xc3\xa9sz l\xc3\xa9trehoz\xc3\xa1sa \xc3\xa9s kit\xc3\xb6lt\xc3\xa9se_NEWLINE_        MimeBodyPart p1 = new MimeBodyPart();_NEWLINE_        p1.setText("Ez az email els\xc5\x91 r\xc3\xa9sze." +_NEWLINE_                    "A m\xc3\xa1sodik r\xc3\xa9sz csatolm\xc3\xa1ny.");_NEWLINE_ _NEWLINE_        // M\xc3\xa1sodik r\xc3\xa9sz l\xc3\xa9trehoz\xc3\xa1sa \xc3\xa9s kit\xc3\xb6lt\xc3\xa9se_NEWLINE_        MimeBodyPart p2 = new MimeBodyPart();_NEWLINE_ _NEWLINE_        // Betessz\xc3\xbck a f\xc3\xa1jlt a m\xc3\xa1sodik r\xc3\xa9szbe_NEWLINE_        FileDataSource fds = new FileDataSource(filename);_NEWLINE_        p2.setDataHandler(new DataHandler(fds));_NEWLINE_        p2.setFileName(fds.getName());_NEWLINE_ _NEWLINE_        // Multipart l\xc3\xa9trehoz\xc3\xa1sa. A t\xc3\xb6rzsr\xc3\xa9szeket hozz\xc3\xa1adjuk._NEWLINE_        Multipart mp = new MimeMultipart();_NEWLINE_        mp.addBodyPart(p1);_NEWLINE_        mp.addBodyPart(p2);_NEWLINE_ _NEWLINE_        // Be\xc3\xa1ll\xc3\xadtjuk a Multipart-ot \xc3\xbczenet tartalm\xc3\xa1nak_NEWLINE_        msg.setContent(mp);_NEWLINE_    }_NEWLINE_ _NEWLINE_    // Egyr\xc3\xa9szes HTML-tartalom be\xc3\xa1ll\xc3\xadt\xc3\xa1sa._NEWLINE_    // B\xc3\xa1rmilyen m\xc3\xa1s t\xc3\xadpus\xc3\xba adat k\xc3\xbcld\xc3\xa9se hasonl\xc3\xb3_NEWLINE_    public static void setHTMLContent(Message msg) throws MessagingException {_NEWLINE_ _NEWLINE_        String html = "<html><head><title>" +_NEWLINE_                        msg.getSubject() +_NEWLINE_                        "</title></head><body><h1>" +_NEWLINE_                        msg.getSubject() +_NEWLINE_                        "</h1><p>This is a test of sending an HTML e-mail" +_NEWLINE_                        " through Java.</body></html>";_NEWLINE_ _NEWLINE_        // HTMLDataSource egy bels\xc5\x91 oszt\xc3\xa1ly_NEWLINE_        msg.setDataHandler(new DataHandler(new HTMLDataSource(html)));_NEWLINE_    }_NEWLINE_ _NEWLINE_    /** Bels\xc5\x91 oszt\xc3\xa1ly, hogy JAF adatforr\xc3\xa1sk\xc3\xa9nt HTML e-mail tartalmat *k\xc3\xbcldhess\xc3\xbcnk     */_NEWLINE_    Static class HTMLDataSource implements DataSource {_NEWLINE_        private String html;_NEWLINE_ _NEWLINE_        public HTMLDataSource(String htmlString) {_NEWLINE_            html = htmlString;_NEWLINE_        }_NEWLINE_ _NEWLINE_        // HTML string InputStream-k\xc3\xa9nt t\xc3\xb6rt\xc3\xa9n\xc5\x91 visszaad\xc3\xa1sa._NEWLINE_        // Minden alkalommal \xc3\xbaj folyamot kell visszaadni._NEWLINE_        public InputStream getInputStream() throws IOException {_NEWLINE_            if (html == null) throw new IOException("Null HTML");_NEWLINE_            return new ByteArrayInputStream(html.getBytes());_NEWLINE_        }_NEWLINE_ _NEWLINE_        public OutputStream getOutputStream() throws IOException {_NEWLINE_            throw new IOException("This DataHandler cannot write HTML");_NEWLINE_        }_NEWLINE_ _NEWLINE_        public String getContentType() {_NEWLINE_            return "text/html";_NEWLINE_        }_NEWLINE_ _NEWLINE_        public String getName() {_NEWLINE_            return "JAF text/html dataSource to send e-mail only";_NEWLINE_        }_NEWLINE_    }_NEWLINE_ _NEWLINE_}'