Created
March 17, 2013 04:14
-
-
Save khannedy/5180073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eecchhoo.email; | |
import org.apache.commons.mail.DefaultAuthenticator; | |
import org.apache.commons.mail.EmailException; | |
import org.apache.commons.mail.HtmlEmail; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
/** | |
* @author Eko Kurniawan Khannedy | |
*/ | |
public class SendHtmlEmailApp { | |
public static void main(String[] args) throws EmailException, FileNotFoundException { | |
// load file html | |
Scanner scanner = new Scanner(new File("email.html")); | |
StringBuilder builder = new StringBuilder(); | |
while (scanner.hasNextLine()) { | |
builder.append(scanner.nextLine()); | |
builder.append("\n"); | |
} | |
// ambil string html | |
String html = builder.toString(); | |
HtmlEmail email = new HtmlEmail(); | |
// konfigurasi | |
email.setHostName("smtp.googlemail.com"); | |
email.setSmtpPort(465); | |
email.setAuthenticator(new DefaultAuthenticator("username", "password")); | |
email.setSSLOnConnect(true); | |
email.setFrom("echo.khannedy@gmail.com"); | |
email.addTo("echo.khannedy@gmail.com"); | |
email.setSubject("Contoh Email"); | |
// gunakan metode setHtmlMsg('<html>isi<html>') | |
email.setHtmlMsg(html); | |
// kirim email | |
email.send(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment