Green mail java
A blast from the past!
"Green Mail" is a term that was popular in the early days of email, particularly in the 1980s and 1990s. It refers to the practice of sending unsolicited, bulk email messages, often with the intention of spamming or phishing.
In Java, you can create a simple "Green Mail" program to send email messages using the JavaMail API. Here's an example:
Note: This example uses the JavaMail API, which is not included in the standard Java distribution. You'll need to download and add the JavaMail library to your project.
GreenMail.java
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class GreenMail {
public static void main(String[] args) {
// Set up the email server
Properties props = new Properties();
props.put("mail.smtp.host", "your-smtp-server");
props.put("mail.smtp.port", "your-smtp-port");
props.put("mail.smtp.auth", "true");
// Create a session
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("your-email-username", "your-email-password");
}
});
// Create a message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("your-email-username", "Your Name"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress("recipient-email-username"));
message.setSubject("Hello, World!");
message.setText("This is a test email message.");
// Send the message
Transport.send(message);
}
}
How to use:
- Replace the placeholders (
your-smtp-server
,your-smtp-port
,your-email-username
,your-email-password
, andrecipient-email-username
) with your actual email server settings and email addresses. - Compile the Java program using
javac
and run it usingjava
. - The program will send an email message to the specified recipient.
Important note: Sending unsolicited, bulk email messages is considered spamming and is illegal in many jurisdictions. This example is intended for educational purposes only and should not be used to send spam or phishing emails. Always respect email recipients' privacy and consent when sending email messages.