List of usage examples for javax.mail PasswordAuthentication PasswordAuthentication
public PasswordAuthentication(String userName, String password)
From source file:org.lf.yydp.service.film.BuyTicketService.java
/** * :?//from ww w . j a va 2 s . c o m * @param receiver */ public void sendEmail(String receiver) { Properties p = null; InputStream inputSteam = null; String senter = null; String Subject = null; String Content = null; try { p = new Properties(); inputSteam = BuyTicketService.class.getClassLoader().getResourceAsStream("mail.properties"); p.load(inputSteam); final String uname = p.getProperty("mail.uname"); final String license = p.getProperty("mail.license"); senter = p.getProperty("mail.senter"); Subject = p.getProperty("mail.subject"); Content = p.getProperty("mail.content"); Authenticator authenticator = new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(uname, license); } }; Session session = Session.getInstance(p, authenticator); MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(senter)); msg.setRecipient(RecipientType.TO, new InternetAddress(receiver)); msg.setSubject(Subject); msg.setContent(Content, "text/html;charset=utf-8"); Transport.send(msg); } catch (Exception e) { e.printStackTrace(); } finally { try { if (inputSteam != null) { inputSteam.close(); } } catch (Exception e2) { e2.printStackTrace(); } } }
From source file:com.mimp.hibernate.HiberMail.java
public static void generateAndSendEmail2(String correo, String pass_plano, String user) { final String username = "formacionadopcion@gmail.com"; final String password = "cairani."; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/*from www . jav a 2 s .c o m*/ }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("formacionadopcion@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(correo)); message.setSubject("Sistema de adopciones"); message.setText("Estimado solicitante," + "\n\n Bienvenido al SISTEMA INFORM?TICO DEL REGISTRO NACIONAL DE ADOPCIONES, " + "sus credenciales para inscribirse al taller son las siguientes:" + "\n\n Usuario: " + user + "\n\n Contrasea: " + pass_plano // + "\n\n Para ingresar al sistema realizar lo siguiente, " // + "\n\n" // + "\n\n" // + "\n\n A. Click directamente en el siguiente link: " // + "\n\n" // + "\n\n 1. Click: http://app.mimp.gob.pe:8080/sirna " // + "\n\n 2. Ingresar con el usuario y contrasea mencionadas lneas arriba. " // + "\n\n" // + "\n\n B. En caso no funcione el link, ingresar al sistema desde la pgina web: " // + "\n\n" // + "\n\n 1. Ingresar a la pgina web: www.mimp.gob.pe " // + "\n\n 2. En la barra de men Direcciones Generales? submen Vicemin. Pob. Vulnerables? seleccionar Adopciones? " // + "\n\n 3. Click en SIRNA Sistema Informtico del Registro Nacional de Adopciones? " // + "\n\n 4. Ingresar con el usuario y contrasea mencionadas lneas arriba. " // + "\n\n" // + "\n\n A travs del SIRNA usted podr realizar las siguientes acciones: " // + "\n\n" // + "\n\n - Inscribirse a uno de los talleres programados. " // + "\n\n - Descargar las lecturas de su taller. " // + "\n\n - Revisar el estado del proceso de adopcin. " // + "\n\n - Cambiar su contrasea. " // + "\n\n" // + "\n\n Para continuar con el proceso, por favor ingresar al sistema e inscribirse a uno de los talleres programados, hasta un da antes de inicio del taller y/o las bacantes se " // + "\n\n encuentres disponibles. " + "\n\n" + "\n\n De tener alguna complicacin y no fue posible su ingreso al sistema, comunicarse inmediatamente con la unidad de adopcin correspondiente. " + "\n\n" + "\n\n Atentamente, " + "\n\n" + "\n\n Direccin General de Adopciones " + "\n\n" + "\n\n Ministerio de la Mujer y Poblaciones Vulnerables " + "\n\n "); Transport.send(message); /* } catch (Exception ex) { */ } catch (Exception ex) { } /*catch (MessagingException e) { throw new RuntimeException(e); }*/ }
From source file:com.pinterest.deployservice.email.SMTPMailManagerImpl.java
private Authenticator getAuthenticator() { if (!StringUtils.isEmpty(userName)) { return new Authenticator() { @Override/*www. j ava2s.c om*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }; } else { return null; } }
From source file:Security.EmailSender.java
/** * Metda sendUerAuthEmail sli na generovanie a zaslanie potvrdzovacieho emailu, ktor sli na overenie zadanho emailu pouvatea, novo registrovanmu pouvateovi. * @param email - emailov adresa pouvatea, ktormu bude zalan email * @param userToken - jedine?n 32 znakov identifiktor registrcie pouvatea * @param firstName - krstn meno pouvatea * @param lastName - priezvisko pouvatea *///from w ww . ja v a2 s .c o m public void sendUserAuthEmail(String email, String userToken, String firstName, String lastName) { String name = "NONE"; String surname = "NONE"; if (firstName != null) { name = firstName; } if (lastName != null) { surname = lastName; } 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("Confirmation email from GPSWebApp server!!!"); //message.setText(userToken); message.setSubject("Confirmation email from GPSWebApp server!!!"); if (system.startsWith("Windows")) { message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ", please confirm your email by clicking on link ...</h1><a href=http://localhost:8084/GPSWebApp/TryToAcceptUser.jsp?token=" + userToken + "&email=" + email + ">LINK</a></body></html>", "text/html"); } else { message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ", please confirm your email by clicking on link ...</h1><a href=http://gps.kpi.fei.tuke.sk/TryToAcceptUser.jsp?token=" + userToken + "&email=" + email + ">LINK</a></body></html>", "text/html"); } Transport.send(message); FileLogger.getInstance().createNewLog("Successfuly sent email to user " + email + "."); } catch (MessagingException e) { FileLogger.getInstance().createNewLog("ERROR: cannot sent email to user " + email + "."); } }
From source file:sk.mlp.security.EmailSender.java
/** * Metda sendUerAuthEmail sli na generovanie a zaslanie potvrdzovacieho emailu, ktor sli na overenie zadanho emailu pouvatea, novo registrovanmu pouvateovi. * @param email - emailov adresa pouvatea, ktormu bude zalan email * @param userToken - jedine?n 32 znakov identifiktor registrcie pouvatea * @param firstName - krstn meno pouvatea * @param lastName - priezvisko pouvatea *//*www.j av a2s.co m*/ public void sendUserAuthEmail(String email, String userToken, String firstName, String lastName) { String name = "NONE"; String surname = "NONE"; if (firstName != null) { name = firstName; } if (lastName != null) { surname = lastName; } 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("Confirmation email from gTraxxx app!!!"); //message.setText(userToken); message.setSubject("Confirmation email from gTraxxx app!!!"); if (system.startsWith("Windows")) { message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ", please confirm your email by clicking on link ...</h1><a href=http://localhost:8080/gTraxxx/TryToAcceptUser.jsp?token=" + userToken + "&email=" + email + ">LINK</a></body></html>", "text/html"); } else { message.setContent("<html><head><meta charset=\"Windows-1250\"></head><body><h1>Hello " + name + " " + surname + ", please confirm your email by clicking on link ...</h1><a href=http://gps.kpi.fei.tuke.sk/TryToAcceptUser.jsp?token=" + userToken + "&email=" + email + ">LINK</a></body></html>", "text/html"); } Transport.send(message); FileLogger.getInstance().createNewLog("Successfuly sent email to user " + email + "."); } catch (MessagingException e) { FileLogger.getInstance().createNewLog("ERROR: cannot sent email to user " + email + "."); } }
From source file:com.gazbert.bxbot.core.mail.EmailAlerter.java
public void sendMessage(String subject, String msgContent) { if (sendEmailAlertsEnabled) { final Session session = Session.getInstance(smtpProps, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpConfig.getAccountUsername(), smtpConfig.getAccountPassword()); }// w ww. ja v a2s. co m }); try { final Message message = new MimeMessage(session); message.setFrom(new InternetAddress(smtpConfig.getFromAddress())); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(smtpConfig.getToAddress())); message.setSubject(subject); message.setText(msgContent); LOG.info(() -> "About to send following Email Alert with message content: " + msgContent); Transport.send(message); } catch (MessagingException e) { // not much we can do here, especially if the alert was critical - the bot is shutting down; just log it. LOG.error("Failed to send Email Alert. Details: " + e.getMessage(), e); } } else { LOG.warn("Email Alerts are disabled. Not sending the following message: Subject: " + subject + " Content: " + msgContent); } }
From source file:org.openmrs.module.reporting.report.processor.EmailReportProcessor.java
/** * Returns the email session/*from ww w.j av a 2 s. c o m*/ */ public Session getSession() { if (session == null) { AdministrationService as = Context.getAdministrationService(); Properties p = new Properties(); p.put("mail.transport.protocol", as.getGlobalProperty("mail.transport_protocol", "smtp")); p.put("mail.smtp.host", as.getGlobalProperty("mail.smtp_host", "localhost")); p.put("mail.smtp.port", as.getGlobalProperty("mail.smtp_port", "25")); // mail.smtp_port p.put("mail.smtp.auth", as.getGlobalProperty("mail.smtp_auth", "false")); // mail.smtp_auth p.put("mail.debug", as.getGlobalProperty("mail.debug", "false")); p.put("mail.from", as.getGlobalProperty("mail.from", "")); final String user = as.getGlobalProperty("mail.user", ""); final String password = as.getGlobalProperty("mail.password", ""); if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password)) { session = Session.getInstance(p, new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user, password); } }); } else { session = Session.getInstance(p); } } return session; }
From source file:pmp.springmail.TestDrive.java
void sendEmailViaPlainMail(String text) { Authenticator authenticator = new Authenticator() { @Override//from w ww .ja va 2 s .c om protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(USER, PASS); } }; Session session = Session.getInstance(props, authenticator); Message message = new MimeMessage(session); try { message.setFrom(new InternetAddress(FROM)); message.setRecipient(Message.RecipientType.TO, new InternetAddress(TO)); message.setSubject("Plain JavaMail Test"); message.setText(DATE_FORMAT.format(new Date()) + " " + text); Transport.send(message); } catch (Exception e) { System.err.println(e.getClass().getSimpleName() + " " + e.getMessage()); } }
From source file:com.unilever.audit.services2.ForgetPassword.java
@GET @Path("Email/{email}") @Produces("application/json") public String LoginIn(@PathParam("email") String email) throws IOException { boolean status = true; String error = null;/* w w w . ja v a2 s. c o m*/ JSONObject result = new JSONObject(); Map<String, Object> hm = new HashMap<String, Object>(); hm.put("email", email); Merchandisers merchidisers = (Merchandisers) merchandisersFacadeREST .findOneByQuery("Merchandisers.findByEmail", hm); if (merchidisers == null) { status = false; error = "invalid email"; } else { Properties props = new Properties(); final String from = ""; final String password = ""; props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.user", from); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.password", password); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, password); } }); session.setDebug(true); try { MimeMessage msg = new MimeMessage(session); msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, email); msg.setSubject("Unilever Confirmation"); msg.setSentDate(new Date()); msg.setText(""); Transport.send(msg); } catch (MessagingException ex) { // status = false; // error="Error Sending Email"; ex.printStackTrace(); } } result.put("status", status); result.put("error", error); System.out.println("----------------" + result.toString()); return result.toString(); }
From source file:NotificationMessage.java
static void sendMail(String toUser, Severity s) { // Recipient's email ID needs to be mentioned. //String to = "abhiyank@gmail.com";//change accordingly // Sender's email ID needs to be mentioned String from = "mdtprojectteam16@gmail.com";//change accordingly final String username = "mdtprojectteam16";//change accordingly final String password = "mdtProject16";//change accordingly // Assuming you are sending email through relay.jangosmtp.net String host = "smtp.gmail.com"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "587"); // Get the Session object. Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/*from w w w . ja v a2 s .c om*/ }); try { // Create a default MimeMessage object. javax.mail.Message message1 = new MimeMessage(session); // Set From: header field of the header. message1.setFrom(new InternetAddress(from)); // Set To: header field of the header. message1.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toUser)); // Set Subject: header field message1.setSubject("Alert Message From Patient"); // Now set the actual message message1.setText(messageMap.get(s)); // Send message Transport.send(message1); System.out.println("Sent message successfully...."); } catch (MessagingException e) { throw new RuntimeException(e); } }