Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String to = "abc@example.com";
- String user = "sp@example.com";
- String pass = "1234";
- Properties props = new Properties();
- props.put("mail.smtp.host", "smtp.example.com");
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.starttls.enable", "true");
- Session session = Session.getInstance(props,new javax.mail.Authenticator()
- {
- protected PasswordAuthentication getPasswordAuthentication()
- {
- return new PasswordAuthentication(user,pass);
- }
- });
- session.setDebug(true);
- try
- {
- /* Create an instance of MimeMessage,
- it accept MIME types and headers
- */
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress(user));
- message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
- message.setSubject(sub);
- message.setText(msg);
- /* Transport class is used to deliver the message to the recipients */
- Transport.send(message);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
Add Comment
Please, Sign In to add comment