Class SmtpTransport
java.lang.Object
com.codename1.backend.mail.MailTransport
com.codename1.backend.mail.smtp.SmtpTransport
Sends mail to an SMTP server: a provider's submission endpoint, a relay, or a mail server of one's own.
cn1.mail.url=smtp://apikey:secret@smtp.example.com:587
smtp:// connects in the clear and upgrades with STARTTLS before anything
else is said; a server that does not offer it is refused. smtps://
speaks TLS from the first byte, as port 465 does. The defaults are port
587 and 465. A user name and password in the URL are percent-encoded where
they contain @, : or /.
| Setting | Default | |
|---|---|---|
cn1.mail.username, cn1.mail.password |
credentials, when the URL carries none | |
cn1.mail.smtp.starttls |
true |
false sends in the clear to a server with no STARTTLS -- a relay on localhost |
cn1.mail.smtp.auth |
plain, login or xoauth2; unset takes what the server offers. With xoauth2 the password is an OAuth 2 access token |
|
cn1.mail.smtp.helo |
localhost |
the name the client gives for itself |
cn1.mail.smtp.ca |
a PEM file of certificates to trust instead of the system's | |
cn1.mail.timeout.connect |
5000 | milliseconds a connection may take to open |
cn1.mail.timeout.read |
60000 | milliseconds a reply may take |
cn1.mail.pool.max |
2 | idle connections kept for the next mail |
cn1.mail.pool.idle |
30000 | milliseconds an idle connection is kept |
A password is never sent over a connection that is not encrypted, whatever the settings say.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOpenssmtp:andsmtps:URLs; what the generated wiring registers. -
Constructor Summary
ConstructorsConstructorDescriptionSmtpTransport(String url, Config config) A transport forurl, with the settings ofconfig, which may be null. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes connections it holds.getHost()The server's host name.getName()What this transport is:smtp,ses,memory,log.intgetPort()The server's port.booleanWhether the transport could reach its server the last time it tried.voidHands one mail over, returning when the other side has taken it.
-
Constructor Details
-
SmtpTransport
A transport forurl, with the settings ofconfig, which may be null. Nothing connects until the first mail.- Throws:
IOException
-
-
Method Details
-
getName
Description copied from class:MailTransportWhat this transport is:smtp,ses,memory,log.- Specified by:
getNamein classMailTransport
-
getHost
The server's host name. -
getPort
public int getPort()The server's port. -
send
Description copied from class:MailTransportHands one mail over, returning when the other side has taken it.
Throws a
MailExceptionwhoseMailException.isPermanent()says whether trying again could help; any other IOException is taken to be a failure of the connection, and is retried.from: the address a bounce goes to, without a display namerecipients: the addresses to deliver to, without display namesmime: the whole message, CRLF line endings, not dot-stuffed
- Specified by:
sendin classMailTransport- Throws:
IOException
-
isHealthy
public boolean isHealthy()Description copied from class:MailTransportWhether the transport could reach its server the last time it tried. One that has not tried yet is healthy.- Overrides:
isHealthyin classMailTransport
-
close
public void close()Description copied from class:MailTransportCloses connections it holds. Never throws.- Specified by:
closein classMailTransport
-