Skip navigation


Barusan ada anak-anak 2006 yang minta diajarin make JavaMail API. Padahal gw juga hampir gak pernah make. Setelah googling bentar akhirnya dapet juga contoh source codenya.

API ini digunakan untuk melakukan penanganan komunikasi email
Sebelumnya harus download dulu librarynya di sini.

Berikut source codenya.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import javax.mail.*;
import javax.mail.internet.*;

import java.util.Properties;

/**
 *
 * @author Petra Barus
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        props.setProperty("mail.transport.protocol", "smtp");
        //USERNYA DIGANTI
        //props.setProperty("mail.smtp.port", "587");
        props.setProperty("mail.host", "students.itb.ac.id");
        props.setProperty("mail.user", "petrakeren");
        props.setProperty("mail.password", "password");
        Session mailSession = Session.getDefaultInstance(props, null);
        Transport transport = mailSession.getTransport();
        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject("Ngetes Java Mail buat Plain");
        message.setContent("Ini Test", "text/plain");
        message.addRecipient(Message.RecipientType.TO,
                //TUJUANNYA DIGANTI JUGA
                new InternetAddress("if15059@students.if.itb.ac.id"));
        transport.connect();
        transport.sendMessage(message,
                message.getRecipients(Message.RecipientType.TO));
        transport.close();
        System.out.println("DONE!");
    }
}

One Comment

  1. cool posting bro😀


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: