title: How to send mail in Java having only the from and to and subject and message?
body: <p>I am using the following code to send mail:</p>
  
  <pre><code>protected void mailSettings() {
      Object lookedUp = null;
      String mailSettingValues[] = null;
      try {
          InitialContext initialContext = new InitialContext();
          lookedUp = initialContext.lookup("java:/comp/env/mailsettings");
          mailSettingValues = lookedUp.toString().split(",");
          smtphost = mailSettingValues[0];
          port = mailSettingValues[1];
          username = mailSettingValues[2];
          password = mailSettingValues[3];
      } catch (NamingException e) {
          e.printStackTrace();
      }
  
      m_properties = new Properties();
      m_properties.put("mail.smtp.host", smtphost);
      m_properties.put("mail.smtp.auth", "true");
      m_properties.put("mail.smtp.starttls.enable", "true");
      m_properties.put("mail.smtp.port", port);
  
      m_Session = Session.getDefaultInstance(m_properties,
              new Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication(username, password);
                  }
              });
  
  }
  
  public void sendMail(String mail_from, String mail_to, String mail_subject,
          String m_body) {
      try {
          m_simpleMessage = new MimeMessage(m_Session);
          m_fromAddress = new InternetAddress(mail_from);
          m_toAddress = new InternetAddress(mail_to);
  
          m_simpleMessage.setFrom(m_fromAddress);
          m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
          m_simpleMessage.setSubject(mail_subject);
  
          m_simpleMessage.setContent(m_body, "text/plain");
  
          Transport.send(m_simpleMessage);
      } catch (MessagingException ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p>As of this code we need to have email from address and the password for the same, but I would like to send mail to <code>to_email</code> address without the authentication(getting user password).</p>
  
  <p>How can this be done?</p>
  
  <p>I need to do the following things:</p>
  
  <ol>
  <li>get the from address from properties or context file</li>
  <li>get the to address from properties or context file</li>
  <li>send mail to <code>to_address</code> without authenticating the from address</li>
  </ol>