Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // packages
- // imports
- public class SendMail {
- public static void sendMail(double price) {
- 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("mymail@gmail.com", "***"); // here your mail or pass of the test
- }
- });
- session.setDebug(true);
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("mymail@gmail.com"));
- Address[] toUser = InternetAddress
- .parse("mymail@gmail.com");
- message.setRecipients(Message.RecipientType.TO, toUser);
- message.setSubject("Send email with new price");
- message.setText("New price is: $"+price);
- Transport.send(message);
- System.out.println("Sending mail completed!!!");
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment