为什么JavaMail使用System.getProperties()?

Ash*_*win 2 java jakarta-mail system-properties

为什么我们需要添加类似的属性

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);
Run Code Online (Sandbox Code Playgroud)

到系统属性发送邮件.为什么它应该是特定的系统属性?

Mar*_*son 7

您实际上不需要将它们添加到系统属性中.

如果您创建一个新的Properties实例并使用您的属性填充它,它仍然可以正常工作.