Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- //processRequest(request, response);
- String login = request.getParameter("login");
- String senha = request.getParameter("senha");
- String email = request.getParameter("email");
- String assunto = "Cadastro de dados do EccomeceJSP2";
- EnviarEmailGmail gm = new EnviarEmailGmail();
- gm.enviarGmail(email, assunto, login, senha);
- public class EnviarEmailGmail {
- static Session session;
- public void enviarGmail(String email, String assunto, String login, String senha){
- try {
- final String username = "meuemail@gmail.com";
- final String password = "minhasenha";
- 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");
- props.put("mail.smtp.socketFactory.port", "465");
- props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
- props.put("mail.smtp.socketFactory.fallback", "false");
- session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("meuemail@gmail.com"));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse(email));
- message.setSubject(assunto);
- //message.setText("Seu cadastro foi realizado com sucesso e seu login e senha será <br> " + "Login:" + login + "Senha:" + senha);
- MimeMultipart multipart2 = new MimeMultipart("related");
- // first part (the html)
- BodyPart messageBodyPart = new MimeBodyPart();
- String htmlText = "<H3>Seu cadastro foi realizado com sucesso e seu login e senha será:</H3><br><b>Login:+login+</b><br><b>Senha:+senha+</b><br><br><img src="cid:image">";
- messageBodyPart.setContent(htmlText, "text/html");
- // add it
- multipart2.addBodyPart(messageBodyPart);
- // second part (the image)
- messageBodyPart = new MimeBodyPart();
- DataSource fds = new FileDataSource
- ("C:\imagens\eccomerce.JPG");
- messageBodyPart.setDataHandler(new DataHandler(fds));
- messageBodyPart.setHeader("Content-ID","<image>");
- // add it
- multipart2.addBodyPart(messageBodyPart);
- // put everything together
- message.setContent(multipart2);
- Transport.send(message);
- System.out.println("Done");
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment