I'm developing a web application using jsp and servlet and I would like it when sending the email it passes an image and the login and password but the email only send the image and does not send the login and password. / p>
Image with error
Servlet
protectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{//processRequest(request,response);Stringlogin=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);
Class responsible for shipping
public class EnviarEmailGmail {
static Session session;
public void enviarGmail(String email, String assunto, String login, String senha){
try {
final String username = "[email protected]";
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("[email protected]"));
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);
}
}
}