Yes, you can! It'll take a little work but it's definitely possible.
First, you'll need javax.mail.jar found here.
Next, you need to write something along the lines of this to write an email (more info can be found at the link above):
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.swing.*;
public class EmailProgram {
public static void main(String[] args) {
String nameString, emailString;
nameString = JOptionPane.showInputDialog("Enter your name", "John Doe");
emailString = JOptionPane.showInputDialog("Enter your email", "john@doe.com");
final String username = "REDACTED EMAIL ADDRESS";
final String password = "REDACTED PASSWORD";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("REDACTED EMAIL ADDRESS"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(emailString));
message.setSubject("Your Grade");
message.setText("Hi " + nameString + "!\n" + "Your grade has been calculated. It is ");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}