~/ learn/ comp-348/ cards/ Sending: Session, MimeMessage, Transport
1 of 5

The four SMTP properties and an authenticated Session

The four SMTP properties and an authenticated Session

Answer

Properties props = new Properties(); props.put("mail.smtp.host", server); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user, password); } });

getInstance opens no connection; it only records configuration. The anonymous Authenticator is a callback the transport invokes later, once it has seen the server advertise AUTH — which is why a wrong password fails at send time and not here.

Jakarta Mail API §Session, §MimeMessage, §Transport

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/71324384-7126-4b0c-8d72-7da21336b971/flashcard utf-8 LF