unsaon pag run ni nga program sa laing computer?
mo run ni sa akong computer pero sa lain dili.
unsaon pag run ni nga program sa laing computer?
mo run ni sa akong computer pero sa lain dili.
import java.util.Properties;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Mailtest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String sender = "eiffel2985@gmail.com";
String recipient ="eiffel2985@gmail.com";
String subject = "test subject";
String messge = "gamai ko otin";
// TODO code application logic here
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("eiffel2985@gmail.com","jul y291985");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(recipient));
message.setSubject(subject);
message.setText(messge);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
download and install JRE (Java Runtime Environment).
if you need to program and compile sa lain computer, (javac.exe class.java), download and install JDK (Java Development Kit).
besides having a JDK and JRE, you should have a mail.jar and activation.jar in your JVM/JDK1.6/JRE/lib/ext. This can be downloaded from Oracle.com as JavaMail v1.4.4.
Similar Threads |
|