title: send mail through java : multiple sender with different mail id
body: <p>I want to send one mail to specified recipient but my sender can have different mail account like outlook or ymail or gmail.
  Is it possible to send an email from different email id to same recipient? I'm using this code : </p>
  
  <pre><code>try
      {final  String from=request.getParameter("from");String smtpServ="",port="";final String pass=request.getParameter("pass");String to=request.getParameter("to");String subject=request.getParameter("subject");String body=request.getParameter("msg");if(from.contains("@gmail.com")){smtpServ="smtp.gmail.com";port="465";}else if(from.contains("@outlook.com") || from.contains("@hotmail.com")){smtpServ="smtp.live.com";port="587";}else if(from.contains("@ymail.com") || from.contains("@yahoo.com") || from.contains("@rocketmail.com") || from.contains("@yahoo.in")){smtpServ="smtp.mail.yahoo.com";port="465";}Properties props = System.getProperties();
            // -- Attaching to default Session, or we could start a new one --
  
      props.put("mail.transport.protocol", "smtp");
      props.put("mail.smtp.starttls.enable","true");
      props.put("mail.smtp.host",smtpServ);        
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.port", port);
  
          Session session1 = Session.getDefaultInstance(props,
          new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication(from,pass);
              }
          });Message message = new MimeMessage(session1);message.setFrom(new InternetAddress(from));             
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
  
      message.setSubject(subject);
       message.setText(body);
            // -- Set some other header information --
  
      message.setHeader("MyMail", "Java Mail Test");
       message.setSentDate(new Date());Transport.send(message);System.out.println("Message sent to"+to+" OK."); }
      catch (Exception ex)
      { ex.printStackTrace();System.out.println("Exception "+ex); }
  </code></pre>