I wrote the whole code and imported mail, activation, com.sun.mail, and smtp jars, but it still giving me an error in starttls this is the error : javax.mail.MessagingException: STARTTLS is required but host does not support STARTTLS,
boolean sessionDebug=false;
Properties props=System.getProperties();
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.required", "true");
final javax.mail.Session mailSession = javax.mail.Session.getInstance(props);
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.put("mail.smtp.debug", "true");
//Session mailSession=Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(msgText);
Transport transport =mailSession.getTransport("smtp");
System.out.println("smtp");
transport.connect(host,user,pass);
System.out.println("smtp connection");
transport.sendMessage(msg,msg.getAllRecipients());
System.out.println("smtp message");
transport.close();
If your mail server doesn't support STARTTLS, you can't use it. Try setting mail.smtp.ssl.enable
instead.
Also, fix all these common JavaMail mistakes.