Last active
August 29, 2015 13:59
-
-
Save kazmura11/10560408 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 mail; | |
import java.io.IOException; | |
import java.io.UnsupportedEncodingException; | |
import javax.mail.MessagingException; | |
public class MailTest { | |
private static final String MAIL_TEMPLATE = "mail.template"; | |
public static void main(String[] args) { | |
System.out.println("Preparing sending mail..."); | |
MailSender ms = new MailSender(); | |
ms.setFromAddress("XXXXXXXXX@gmail.com"); | |
ms.addToAddress("XXXXXXXXX@gmail.com"); | |
ms.setAccount("XXXXXXXXX"); // before @ | |
ms.setPassword("PPPPPPPPP"); // GoogleAccount's Password | |
ms.setSubject("Java mail test"); | |
try { | |
ms.setMailContentFromTemplate(MAIL_TEMPLATE); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
ms.replaceMailContent("\\{toname\\}", "佐藤"); | |
System.out.println("Trying to connect SMTP Server..."); | |
try { | |
ms.send(); | |
} catch (UnsupportedEncodingException e) { | |
e.printStackTrace(); | |
} catch (MessagingException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Sent mail."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment