I’ve sent them, haven’t actually tried receiving them, but the concept is the same:
import javax.mail.*
import javax.mail.internet.*
class Mail {
public static void simpleMail(String from, String to,
String subject, String body) throws Exception {
Properties props = new Properties();
props.putAll([
"mail.smtp.port": "25"
]);
Session session = Session.getDefaultInstance(props);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject(subject);
message.setText(body);
Transport.send(message);
}
}
The details of receiving instead of sending can be found here:
— Jeff