[[io.email]]
= Sending Email

The Spring Framework provides an abstraction for sending email by using the javadoc:org.springframework.mail.javamail.JavaMailSender[] interface, and Spring Boot provides auto-configuration for it as well as a starter module.

TIP: See the {url-spring-framework-docs}/integration/email.html[reference documentation] for a detailed explanation of how you can use javadoc:org.springframework.mail.javamail.JavaMailSender[].

If `spring.mail.host` and the relevant libraries (as defined by `spring-boot-starter-mail`) are available, a default javadoc:org.springframework.mail.javamail.JavaMailSender[] is created if none exists.
The sender can be further customized by configuration items from the `spring.mail` namespace.
See javadoc:org.springframework.boot.autoconfigure.mail.MailProperties[] for more details.

In particular, certain default timeout values are infinite, and you may want to change that to avoid having a thread blocked by an unresponsive mail server, as shown in the following example:

[configprops,yaml]
----
spring:
  mail:
    properties:
      "[mail.smtp.connectiontimeout]": 5000
      "[mail.smtp.timeout]": 3000
      "[mail.smtp.writetimeout]": 5000
----

It is also possible to configure a javadoc:org.springframework.mail.javamail.JavaMailSender[] with an existing javadoc:jakarta.mail.Session[] from JNDI:

[configprops,yaml]
----
spring:
  mail:
    jndi-name: "mail/Session"
----

When a `jndi-name` is set, it takes precedence over all other Session-related settings.
