title: Segregating Springboot app for DEV and PROD Environment for the email app
body: <p>My springboot App is working fine in DEV environment, and now i would like to segregate DEV and PROD environments in order for it to pickup respective code.</p>
  <p>I did go through few of the tutorials got some lead to it but was not able to come conclusion on how to separate out PROD section.</p>
  <p>This app basically sends an email to gmail on form submission from angular app. This is what i have done till now on the springboot app in order to segregate it.</p>
  <p>I have created <code>application-dev.properties</code> and <code>application-prod.properties</code> from the actual <code>application.properties</code> file and added two separate gmail accounts one for DEV and one for PROD. And added the Profiles to POM.xml</p>
  <p>Any help on how to create a PROD environment from the existing code will be very helpful. I am quite new to springboot and how to go about doing profiling for different environments.</p>
  <p>application.properties file (actual file) is :</p>
  <pre><code>server.port=8084
  
  spring.mail.host=smtp.gmail.com
  spring.mail.port=587
  spring.mail.username=test1@gmail.com
  spring.mail.password=xxxxxxxxxxxxx
  spring.mail.properties.mail.smtp.auth=true
  spring.mail.properties.mail.smtp.starttls.enable=true
  </code></pre>
  <p>New application-dev.properties file</p>
  <pre><code>server.port=8084
  spring.mail.host=smtp.gmail.com
  spring.mail.port=587
  spring.mail.username=test1@gmail.com
  spring.mail.password=xxxxxxxxxxxxxxx
  spring.mail.properties.mail.smtp.auth=true
  spring.mail.properties.mail.smtp.starttls.enable=true
  
  spring.profiles.active=@activatedProperties@
  </code></pre>
  <p>New application-prod.properties file</p>
  <pre><code>server.port=8085
  spring.mail.host=smtp.gmail.com
  spring.mail.port=587
  spring.mail.username=test2@gmail.com
  spring.mail.password=xxxxxxxxxxxxxxx
  spring.mail.properties.mail.smtp.auth=true
  spring.mail.properties.mail.smtp.starttls.enable=true
  </code></pre>
  <p>POM.xml file</p>
  <pre><code>&lt;profile&gt;
    &lt;id&gt;dev&lt;/id&gt;
    &lt;properties&gt;
      &lt;activatedProperties&gt;dev&lt;/activatedProperties&gt;
    &lt;/properties&gt;
    &lt;activation&gt;
      &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
    &lt;/activation&gt;
  &lt;/profile&gt;
  &lt;profile&gt;
    &lt;id&gt;prod&lt;/id&gt;
    &lt;properties&gt;
      &lt;activatedProperties&gt;prod&lt;/activatedProperties&gt;
    &lt;/properties&gt;
  &lt;/profile&gt;
  </code></pre>
  <p>Main EmailClientHmwApplication.java file  is as below:</p>
  <pre><code>package com.sami.EmailClientHMW;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class EmailClientHmwApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(EmailClientHmwApplication.class, args);
      }
  
  }
  </code></pre>
  <p>My MailController file which is working with DEV  is as :</p>
  <pre><code>package com.sami.EmailClientHMW.controller;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.mail.SimpleMailMessage;
  import org.springframework.mail.javamail.JavaMailSender;
  import org.springframework.web.bind.annotation.*;
  
  
  @RestController
  public class MailController {
  
      @Autowired
      private JavaMailSender mailSender;
      @GetMapping(&quot;/testsite&quot;)
      public String Testing()
      {
          return &quot;Welcome to HMW Email Client Version..New!!&quot;;
      }
  
      @PostMapping(&quot;/mail&quot;)
      @CrossOrigin
      public String sendmail(@RequestBody MailRequest request) {
          sendSimpleEmail(request.getFrom(), request.getBody(), request.getSubject());
          return &quot;email sent successfully&quot;;
      }
  
      private void sendSimpleEmail(
              String fromEmail,
              String body,
              String subject)
      {
          SimpleMailMessage message = new SimpleMailMessage();
          message.setFrom(&quot;test1@gmail.com&quot;);
          message.setTo(&quot;test1@gmail.com&quot;);
          message.setSubject(subject);
          message.setText(body);
              mailSender.send(message);
          System.out.println(&quot;From DEV Mail Sent Successfully..hmw!!&quot;);
      }
  }
  </code></pre>
  <p>MailRequest file:</p>
  <pre><code>package com.sami.EmailClientHMW.controller;
  
  public class MailRequest {
      private String from;
      private String to;
      private String subject;
      private String body;
  
      public String getFrom() {
          return from;
      }
  
      public void setFrom(String from) {
          this.from = from;
      }
  
      public String getTo() {
          return to;
      }
  
      public void setTo(String to) {
          this.to = to;
      }
  
      public String getSubject() {
          return subject;
      }
  
      public void setSubject(String subject) {
          this.subject = subject;
      }
  
      public String getBody() {
          return body;
      }
  
      public void setBody(String body) {
          this.body = body;
      }
  }
  </code></pre>