List of usage examples for javax.mail PasswordAuthentication PasswordAuthentication
public PasswordAuthentication(String userName, String password)
From source file:com.jvoid.customers.customer.service.CustomerMasterService.java
public void sendEmail(String email, String password) { Properties properties = System.getProperties(); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.auth", false); properties.put("mail.smtp.host", "smtp.gmail.com"); properties.put("mail.smtp.port", 587); Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("test@example.com", "test123"); }/*from w w w . j a v a2 s. c o m*/ }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("toaddress@example.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject("Reset Password"); String content = "Your new password is " + password; message.setText(content); Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:org.codice.ddf.platform.email.impl.SmtpClientImpl.java
Authenticator createAuthenticator() { return new Authenticator() { @Override/*from w w w .j a va 2 s. c om*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }; }
From source file:io.mapzone.arena.EMailHelpDashlet.java
protected void initMailSession() { Properties props = new Properties(); props.put("mail.smtp.host", System.getProperty("mail.smtp.host", smtpHost.get())); props.put("mail.smtp.port", "25"); props.put("mail.smtp.auth", "true"); // TODO uncomment if the mail server contains a correct SSL certificate // props.put( "mail.smtp.starttls.enable", "true" ); // enable STARTTLS // create Authenticator object to pass in Session.getInstance argument Authenticator auth = new Authenticator() { @Override//from w w w. j av a 2 s . co m protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUser.get(), smtpPassword.get()); } }; assert session == null; session = Session.getInstance(props, auth); }
From source file:com.cosmicpush.plugins.smtp.EmailMessage.java
public Authenticator newAuthenticator() { return new Authenticator() { @Override/* w ww . jav a2s. c om*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }; }
From source file:com.huffingtonpost.chronos.servlet.TestConfig.java
@Bean public Session authSession() { final String username = "spluh"; final String password = "abracaduh"; Session session = Session.getInstance(authMailProperties(), new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/*from ww w . j ava2s . c om*/ }); return session; }
From source file:com.app.mail.DefaultMailSender.java
private static Session _authenticateOutboundEmailAddress() { return Session.getInstance(PropertiesUtil.getConfigurationProperties(), new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(PropertiesValues.OUTBOUND_EMAIL_ADDRESS, PropertiesValues.OUTBOUND_EMAIL_ADDRESS_PASSWORD); }/*from w ww.j a va 2s. c o m*/ }); }
From source file:Security.EmailSender.java
/** * Metda sendUserPasswordRecoveryEmail je ur?en na generovbanie a zaslanie pouvateovi email s obnovenm jeho zabudnutho hesla. * @param email - pouvatesk email/* ww w. j a v a 2 s . c om*/ */ public void sendUserPasswordRecoveryEmail(String email) { try { DBLoginFinder finder = new DBLoginFinder(); ArrayList<String> results = finder.getUserInformation(email); String name = "NONE"; String surname = "NONE"; if (results.get(0) != null) { name = results.get(0); } if (results.get(1) != null) { surname = results.get(1); } Properties props = new Properties(); props.put("mail.smtp.host", server); 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(userName, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("skuska.api.3@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject("Your password to GPSWebApp server!!!"); //message.setText(userToken); message.setSubject("Your password to GPSWebApp server!!!"); message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ",</h1><br>your paassword to access GPSWebApp server is <b>" + results.get(5) + "</b>. <br>Please take note that you can change it in your settings. Have a pleasant day.</body></html>", "text/html"); Transport.send(message); FileLogger.getInstance() .createNewLog("Successfuly sent password recovery email to user " + email + "."); } catch (MessagingException e) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } }
From source file:sk.mlp.security.EmailSender.java
/** * Metda sendUserPasswordRecoveryEmail je ur?en na generovbanie a zaslanie pouvateovi email s obnovenm jeho zabudnutho hesla. * @param email - pouvatesk email/*from w w w.ja va 2s . c o m*/ */ public void sendUserPasswordRecoveryEmail(String email) { try { DatabaseServices databaseServices = new DatabaseServices(); User user = databaseServices.findUserByEmail(email); String name = "NONE"; String surname = "NONE"; if (user.getFirstName() != null) { name = user.getFirstName(); } if (user.getLastName() != null) { surname = user.getLastName(); } Properties props = new Properties(); props.put("mail.smtp.host", server); 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(userName, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("skuska.api.3@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); message.setSubject("Your password to GPSWebApp server!!!"); //message.setText(userToken); message.setSubject("Your password to GPSWebApp server!!!"); message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ",</h1><br>your paassword to access GPSWebApp server is <b>" + user.getPass() + "</b>. <br>Please take note that you can change it in your settings. Have a pleasant day.</body></html>", "text/html"); Transport.send(message); FileLogger.getInstance() .createNewLog("Successfuly sent password recovery email to user " + email + "."); } catch (MessagingException e) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } } catch (Exception ex) { FileLogger.getInstance() .createNewLog("ERROR: Cannot sent password recovery email to user " + email + "."); } }
From source file:info.raack.appliancedetection.common.email.SMTPEmailSender.java
public void sendGeneralEmail(String recipientEmail, String subject, String body) { Session session = Session.getDefaultInstance(emailProperties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/* w w w. j a va2s . co m*/ }); Message message = new MimeMessage(session); try { message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail)); message.setSubject(subject + (!environment.equals("prod") ? " [" + environment + "]" : "")); message.setText(body); } catch (Exception e) { throw new RuntimeException("Could not create message", e); } emailQueue.add(message); }
From source file:com.datatorrent.lib.io.SmtpOutputOperator.java
private void reset() { if (!setupCalled) { return;/*from w ww . j av a 2 s . com*/ } if (!StringUtils.isBlank(smtpPassword)) { properties.setProperty("mail.smtp.auth", "true"); properties.setProperty("mail.smtp.starttls.enable", "true"); if (useSsl) { properties.setProperty("mail.smtp.socketFactory.port", String.valueOf(smtpPort)); properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); properties.setProperty("mail.smtp.socketFactory.fallback", "false"); } auth = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUserName, smtpPassword); } }; } properties.setProperty("mail.smtp.host", smtpHost); properties.setProperty("mail.smtp.port", String.valueOf(smtpPort)); session = Session.getInstance(properties, auth); resetMessage(); }