title: Sending email on behalf of Google group programatically
body: <p>I would like to know if it is possible and if so how to send an email on behalf of the Google group. </p>
  
  <p>I am using Google Apps and I currently have a user no-reply@... that I am using to send emails from (e.g.password remainders). However I don't like that this is the actual user in the system as I feel that it should only be a group. </p>
  
  <p>The code I am using at the moment can be seen below </p>
  
  <pre><code>private final String mailPassword = "somepass";
  private final String mailUserName = "no-reply@";
  
  public MailService() {
      initializeSession();
  }
  
  public void sendMailWithPassword(String email, String content) {
  
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(mailUserName));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
  
      message.setSubject("Password Reminder");
      message.setText(content);
  
      Transport.send(message);
  }
  
  private void initializeSession() {
      Properties props = new Properties();
  
      props.put("mail.smtp.host", "smtp.gmail.com");
      props.put("mail.smtp.socketFactory.port", "465");
      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.port", "465");
  
      session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
  
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
              return new PasswordAuthentication(mailUserName, mailPassword);
          }
      });
  }
  </code></pre>
  
  <p>However, if I change <code>mailUsername</code> to a group name I get the following exception</p>
  
  <blockquote>
    <p>421 4.7.0 Temporary System Problem. Try again later (HS). k2sm18720682eep.15</p>
  </blockquote>