When i send email through a java class then show error please tell me solution
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. j9-20020aa78009000000b004fde2dd78b0sm9989611pfi.109 - gsmtp
BlManager bm = new BlManager();
Contactus cu = new Contactus();
String name, email,subject,msg;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException,IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
name = request.getParameter("name");
email = request.getParameter("email");
subject = request.getParameter("subject");
msg = request.getParameter("message");
final String username = "";// your email id
final String password = "";// your password
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.ssl.protocols","TLSv1.2");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
String[] listofIDS = { username, email };
for (String cc : listofIDS) {
message.addRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
}
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
MimeBodyPart textPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
String final_Text = "Name: " + name + "" + "Email: " + email + "" + "Subject: "
+ subject + "" + "Mesaage: " + msg;
textPart.setText(final_Text);
message.setSubject(subject);
multipart.addBodyPart(textPart);
message.setContent(multipart);
message.setSubject("Contact Details");
Transport.send(message);
cu.setName(name);
cu.setEmail(email);
cu.setSubject(subject);
cu.setMessage(msg);
bm.savecontactus(cu);
out.println("<center><h2 style='color:green;'>Email Sent Successfully.</h2>");
} catch (Exception e) {
out.println(e);
}
}
}