Janitha
Wikipedia
Search results
Saturday, October 20, 2012
Java Email Code || using gmail || netbeans
Click Here |
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
.......................................................................
Libraries Download..
Click Here to download .jar files
................................................................................................
..............code start............................................
try {
String body=jTextArea1.getText();-- Body
String email=txtemail.getText();// -- To
// Using SSL
Properties propsSSL = new Properties();
propsSSL.put("mail.transport.protocol", "smtps");
propsSSL.put("mail.smtps.host", "smtp.gmail.com");
propsSSL.put("mail.smtps.auth", "true");
Session sessionSSL = Session.getInstance(propsSSL);
sessionSSL.setDebug(true);
Message messageSSL = new MimeMessage(sessionSSL);
messageSSL.setFrom(new InternetAddress("youremail@gmail.com", "janitha"));//your email messageSSL.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); recipient
messageSSL.setSubject(txtsubject.getText());
messageSSL.setText(body);
Transport transportSSL = sessionSSL.getTransport();
transportSSL.connect("smtp.gmail.com", 465, "youremail@gmail.com", "password");
// youremail@gmail.com---set your email adress
//password ---- set email password
transportSSL.sendMessage(messageSSL, messageSSL.getAllRecipients());
transportSSL.close();
System.out.println("SSL done.");
System.out.println("------------------------------------Email Send------------------------------------");
} catch (Exception e) {
throw new RuntimeException(e);
}
Subscribe to:
Posts (Atom)