Why do we need to add the properties like
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
Session session = Session.getDefaultInstance(props, null);
to the system properties to send a mail. Why should it be specifically system properties?
You don’t actually need to add them to the system properties.
If you create a new Properties instance and populate it with your attributes it will still work just the same.