Created
June 23, 2013 09:23
-
-
Save perforb/5844399 to your computer and use it in GitHub Desktop.
Sending a mail test.
This file contains hidden or 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 sandbox; | |
import java.util.Properties; | |
import javax.mail.Message; | |
import javax.mail.MessagingException; | |
import javax.mail.Session; | |
import javax.mail.Transport; | |
import javax.mail.internet.InternetAddress; | |
import javax.mail.internet.MimeMessage; | |
/** | |
* This sample code is from http://d.hatena.ne.jp/ttshrk/20110517/1305641955. | |
* Depends on https://code.google.com/p/javamail-android/. | |
*/ | |
public class SendingMailTest | |
{ | |
public static void main(String[] args) throws MessagingException | |
{ | |
Properties props = new Properties(); | |
props.put("mail.smtp.host", "smtp.gmail.com"); | |
props.put("mail.host", "smtp.gmail.com"); | |
props.put("mail.smtp.port", "587"); | |
props.put("mail.smtp.auth", "true"); | |
props.put("mail.smtp.starttls.enable", "true"); | |
Session session = Session.getDefaultInstance(props); | |
session.setDebug(true); | |
MimeMessage msg = new MimeMessage(session); | |
msg.setSubject("件名", "utf-8"); | |
msg.setFrom(new InternetAddress("[email protected]")); | |
msg.setSender(new InternetAddress("[email protected]")); | |
msg.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]")); | |
msg.setText("本文", "utf-8"); | |
Transport t = session.getTransport("smtp"); | |
t.connect("Gmail Account - [email protected]", "password"); | |
t.sendMessage(msg, msg.getAllRecipients()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment