title: How do you send 2 emails to two different email addresses in Java?
body: <p>I have created a module for contact us. Here one user can send a mail about his concerns to admin and admin can send a reply mail to that particular user. So I have created 2 different mail templates, But I don't know how to send both at the same time.</p>
  
  <p>Now I have completed sending reply email to  user, but I have not done sending mail to admin user.</p>
  
  <p>My code for sending reply mail to user:</p>
  
  <pre><code>package com.spring.test.service;
  
  import java.io.IOException;
  import java.util.Properties;
  
  import javax.mail.internet.InternetAddress;
  
  import org.json.JSONObject;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.mail.MailSender;
  import org.springframework.mail.SimpleMailMessage;
  import org.springframework.mail.javamail.JavaMailSenderImpl;
  import org.springframework.web.client.RestTemplate;
  
  public class MailMail {
  
      private MailSender mailSender;
  
      @Autowired
      @Qualifier(value = "mailSender")
      public void setMailSender(MailSender mailSender) {  
          this.mailSender = mailSender;
      }  
  
      public void sendMail(String to,  String subject, String msg) {  
          //creating message 
  
          System.out.println("mailsender == " + this.mailSender);
  
          try {
              String from = "emailFromAddress";
  
              JavaMailSenderImpl sender = new JavaMailSenderImpl();
              javax.mail.internet.MimeMessage mimeMessage = sender.createMimeMessage();
              org.springframework.mail.javamail.MimeMessageHelper helper = new org.springframework.mail.javamail.MimeMessageHelper(mimeMessage, false, "utf-8");
              mimeMessage.setContent(msg, "text/html");
              helper.setSubject(subject);
              helper.setFrom(from);
              helper.setTo(to);
  
              sender.setHost("smtp.gmail.com");
              sender.setUsername("emailServerUserName");
              sender.setPassword("emailServerPassword");
              sender.setPort(587);
  
              Properties props = new Properties();
              props.put("mail.smtp.auth",true);
              props.put("mail.smtp.starttls.enable","true");
  
              sender.setJavaMailProperties(props);
              sender.send(mimeMessage);
          } catch(Exception e){
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Can anyone tell me how to send mail to admin users also at a time?</p>