Help with Java practice

Hi all,

my name is Jennifer. I’m quite new about programming. I need some help and advice about how to start and manage this exercise for University practice:

You have to write an email client for sending emails with different characteristics and you came up with a basic public contract like the one below:

public interface EmailService {

void send(Email email);

}

The emails can be sent as plain text or as HTML and emails which are sent outside the company servers need to be logged and have a disclaimer added to the end. What’s worse, the emails could also be encrypted with AES or DES, or even both at the same time. Your boss tells you that in case there are problems when sending the emails you should retry the sending operation up to three times.

Design a simple client with the accompanying class(es) which you consider to be necessary and write a short program inside the standard void main(String[] args) function that would implement the following scenarios by making use of your class(es):

  • sending a plain text email to an outside resource, with a disclaimer added at the end, unencrypted and no retry* sending an HTML email to an internal server (so without the disclaimer), encrypted with DES, with the retry functionality

  • sending an HTML email to an outside resource, with a disclaimer added at the end and encrypted with AES with retries in case of errors

  • sending a plain text email to an outside resource and encrypted first with DES and then with AES*

Here’s the class that I have written for now, I don’t know if it can be accurate to fulfill practice’s requirements by adding some additional methods:

public class SendEmail {

public SendEmail () {}

public void send (String text){
    String host = "smtp.gmail.com";
    String username = "user@email.com";
    String password = "password";
    Properties props = new Properties();
    // set any needed mail.smtps.* properties here
    Session session = Session.getInstance(props, new GMailAuthenticator("user", "password"));
    Message msg = new MimeMessage(session);
    Transport t;
    try {
        msg.setText(text);
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress("stackkinggame@gmail.com", "Stack King"));
        t = session.getTransport("smtps");
        t.connect(host, username, password);
        t.sendMessage(msg, msg.getAllRecipients());
        t.close();
        Gdx.app.log("Email", "Message sent successfully.");
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

class GMailAuthenticator extends Authenticator {
    String user;
    String pw;
    public GMailAuthenticator (String username, String password)
    {
        super();
        this.user = username;
        this.pw = password;
    }
    public PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication(user, pw);
    }
}

}

Thanks everybody in advance. :slight_smile:

//