3

I would like to know if it is possible and if so how to send an email on behalf of the Google group.

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.

The code I am using at the moment can be seen below

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);
        }
    });
}

However, if I change mailUsername to a group name I get the following exception

421 4.7.0 Temporary System Problem. Try again later (HS). k2sm18720682eep.15

ekad
  • 14,436
  • 26
  • 44
  • 46
Boris Horvat
  • 563
  • 2
  • 13
  • 28

0 Answers0