Book Image

Mastering Spring Application Development

By : Anjana Mankale
Book Image

Mastering Spring Application Development

By: Anjana Mankale

Overview of this book

Table of Contents (19 chapters)
Mastering Spring Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sending mail using the @Configuration annotation


We shall demonstrate here how we can send mail using the Spring mail API.

  1. First, we provide all the SMTP details in the .properties file and read it to the class file with the @Configuration annotation. The name of the class is MailConfiguration.

    mail.properties file contents are shown below:

    mail.protocol=smtp
    mail.host=localhost
    mail.port=25
    mail.smtp.auth=false
    mail.smtp.starttls.enable=false
    mail.from=me@localhost
    mail.username=
    mail.password=
    
    @Configuration
    @PropertySource("classpath:mail.properties")
    public class MailConfiguration {
      @Value("${mail.protocol}")
      private String protocol;
      @Value("${mail.host}")
      private String host;
      @Value("${mail.port}")
      private int port;
      @Value("${mail.smtp.auth}")
      private boolean auth;
      @Value("${mail.smtp.starttls.enable}")
      private boolean starttls;
      @Value("${mail.from}")
      private String from;
      @Value("${mail.username}")
      private String username;
      @Value("${mail.password}")
      private...