List of usage examples for javax.mail PasswordAuthentication PasswordAuthentication
public PasswordAuthentication(String userName, String password)
From source file:org.devproof.portal.test.JettyStart.java
public static void main(final String[] args) throws Exception { if (args.length != 5) { System.out.println("JettyStart <DbUser/Pass/Schema> <httpport> <smtphost> <smtpuser> <smtppass>"); return;//from w ww . j av a 2 s . com } Server server = new Server(); SocketConnector connector = new SocketConnector(); // Set some timeout options to make debugging easier. connector.setMaxIdleTime(1000 * 60 * 60); connector.setSoLingerTime(-1); connector.setPort(Integer.valueOf(args[1])); server.setConnectors(new Connector[] { connector }); WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar(System.getProperty("java.io.tmpdir")); bb.addEventListener(new PortalContextLoaderListener()); FilterHolder filter = new FilterHolder(); filter.setInitParameter("applicationClassName", PortalApplication.class.getName()); // servlet.setInitParameter("configuration", "deployment"); filter.setClassName(WicketFilter.class.getName()); filter.setName(WicketFilter.class.getName()); bb.addFilter(filter, "/*", 1); server.addHandler(bb); BasicDataSource datasource = new BasicDataSource(); datasource.setUrl("jdbc:mysql://localhost/" + args[0]); datasource.setUsername(args[0]); datasource.setPassword(args[0]); datasource.setDriverClassName(Driver.class.getName()); new Resource(CommonConstants.JNDI_DATASOURCE, datasource); Properties props = System.getProperties(); props.put("mail.smtp.host", args[2]); props.put("mail.smtp.auth", "true"); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.port", "25"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.debug", "true"); Authenticator auth = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(args[3], args[4]); } }; Session mailSession = Session.getDefaultInstance(props, auth); new Resource(CommonConstants.JNDI_MAIL_SESSION, mailSession); new Resource(CommonConstants.JNDI_PROP_EMAIL_DISABLED, "true"); // START JMX SERVER MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); server.getContainer().addEventListener(mBeanContainer); mBeanContainer.start(); try { System.out.println(">>> STARTING DEVPROOF PORTAL, PRESS ANY KEY TO STOP"); server.start(); while (System.in.available() == 0) { Thread.sleep(5000); } server.stop(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(100); } }
From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java
public static void sendGRUP(String from, String password, String bcc, String sub, String msg, String filename) throws Exception { //Get properties object 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"); //get Session Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, password); }//from w w w . j a v a 2 s .c om }); //compose message try { MimeMessage message = new MimeMessage(session); //message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc)); message.setSubject(sub); message.setText(msg); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Raport teste automat"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); multipart.addBodyPart(messageBodyPart); //message.setContent(multipart); StringWriter writer = new StringWriter(); IOUtils.copy(new FileInputStream(new File(filename)), writer); message.setContent(writer.toString(), "text/html"); //send message Transport.send(message); System.out.println("message sent successfully"); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:MainClass.java
public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("username", "password"); }
From source file:com.mimp.hibernate.HiberMail.java
public static void generateAndSendEmail(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); }/*w w w .ja v 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 Su solicitud de recuperacin de contrasea ha sido procesada. Su usuario y contrasea para acceder a la plataforma de adopciones son los siguientes:" + "\n\n Usuario: " + user + "\n\n Contrasea: " + pass_plano + "\n\n Saludos cordiales, "); Transport.send(message); } catch (Exception ex) { } /*catch (MessagingException e) { throw new RuntimeException(e); }*/ }
From source file:net.kamhon.ieagle.function.email.SendMail.java
public void send(String to, String cc, String bcc, String from, String subject, String text, String emailType) { // Session session = Session.getInstance(props, null); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(emailServerSetting.getUsername(), emailServerSetting.getPassword()); }/* w w w .ja va 2s. c om*/ }); session.setDebug(emailServerSetting.isDebug()); try { Message msg = new MimeMessage(session); if (StringUtils.isNotBlank(from)) { msg.setFrom(new InternetAddress(from)); } else { msg.setFrom(); } msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); if (StringUtils.isNotBlank(cc)) { msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false)); } if (StringUtils.isNotBlank(bcc)) { msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc, false)); } msg.setSubject(subject); if (Emailq.TYPE_HTML.equalsIgnoreCase(emailType)) { msg.setContent(text, "text/html"); } else { msg.setText(text); } msg.setSentDate(new java.util.Date()); Transport.send(msg); } catch (MessagingException mex) { mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); } throw new SystemErrorException(mex); } }
From source file:Utilities.SendEmailUsingGMailSMTP.java
public void enviarCorreo(String correo, String clave) { String to = correo;// w ww. j a v a 2s. c om final String username = "angelicabarrientosvera@gmail.com";//change accordingly final String password = "90445359D10s";//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"); props.put("mail.smtp.ssl.trust", "smtp.gmail.com"); // Get the Session object. Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { // Create a default MimeMessage object. Message message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(to)); // Set To: header field of the header. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); // Set Subject: header field message.setSubject("Testing Subject"); // Now set the actual message message.setText("\n" + "Use esta clave para poder restablecer la contrasea" + "\n" + "Tu cdigo para restaurar su cuenta es:" + clave); // Send message Transport.send(message); System.out.println("Sent message successfully...."); //return true; } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:util.Support.java
/** * Send email by SSL//www .j a v a2 s . c om * * @param toEmail Email of user * @param idActive id active authentication */ public static void sendMail(String toEmail, String idActive) { 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() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(util.Constants.FROM_EMAIL, util.Constants.PASSWORD_EMAIL); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(util.Constants.FROM_EMAIL)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail)); message.setSubject("Authentication registration your account."); if (!idActive.isEmpty()) { message.setText("Dear Mail Crawler," + "\n Click to link to complete the registered , please!" + "\n http://localhost:8084/JudiBlog/active?id=" + idActive + ""); } else { message.setText("OK, thank you!" + "\n You have registed successfully!"); } Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:org.apache.usergrid.apm.service.util.Mailer.java
public static void send(String recipeintEmail, String subject, String messageText) { /*/*from w ww.j a v a2 s. c o m*/ * It is a good practice to put this in a java.util.Properties file and * encrypt password. Scroll down to comments below to see how to use * java.util.Properties in JSF context. */ Properties props = new Properties(); try { props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/email.properties")); } catch (IOException e) { e.printStackTrace(); } final String senderEmail = props.getProperty("mail.smtp.sender.email"); final String smtpUser = props.getProperty("mail.smtp.user"); final String senderName = props.getProperty("mail.smtp.sender.name"); final String senderPassword = props.getProperty("senderPassword"); final String emailtoCC = props.getProperty("instaopsOpsEmailtoCC"); Session session = Session.getDefaultInstance(props, new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUser, senderPassword); } }); session.setDebug(false); try { MimeMessage message = new MimeMessage(session); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(messageText, "text/html"); // Add message text Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); message.setContent(multipart); message.setSubject(subject); InternetAddress senderAddress = new InternetAddress(senderEmail, senderName); message.setFrom(senderAddress); message.addRecipient(Message.RecipientType.CC, new InternetAddress(emailtoCC)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipeintEmail)); Transport.send(message); log.info("email sent"); } catch (MessagingException m) { log.error(m.toString()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.mycompany.login.mb.EmailBean.java
public EmailBean() { SimpleEmail email = new SimpleEmail(); //email.setHostName("smtp-pel.lifemed.com.br"); //email.setSmtpPort(587); // email.setAuthenticator(new DefaultAuthenticator("anderson.freitas", "nub10fr31t4s")); // email.setFrom("anderson.freitas@lifemed.com.br"); //email.setDebug(true); this.propriedades.put("mail.smtp.auth", true); this.propriedades.put("mail.smtp.port", "587"); this.propriedades.put("mail.host", "smtp-pel.lifemed.com.br"); this.propriedades.put("mail.stmp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); this.propriedades.put("mail.smtp.socketFactory..fallback", "false"); this.authentication = new Authenticator() { @Override/* www . ja v a2 s. com*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("anderson.freitas", "nub10fr31t4s"); }; }; }
From source file:com.youxifan.utils.EMailAuthenticator.java
/** * Constructor/* ww w.j av a 2 s .c om*/ * @param username user name * @param password user password */ public EMailAuthenticator(String username, String password) { m_pass = new PasswordAuthentication(username, password); if (username == null || username.length() == 0) { log.info("Username is NULL"); Thread.dumpStack(); } if (password == null || password.length() == 0) { log.info("Password is NULL"); Thread.dumpStack(); } }