⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailtest.java

📁 理想的邮件收发管理
💻 JAVA
字号:
package zx.mmy;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;


public class MailTest {
	@SuppressWarnings("static-access")
	public static void main(String[] args) {

		try {
			Properties props = new Properties();
			Session sendMailSession;
			@SuppressWarnings("unused")
			Store store;
			Transport transport;

			PopupAuthenticator popAuthenticator = new PopupAuthenticator(
					"muchuan69@163.com", "mmy5855342");
			sendMailSession = Session.getInstance(props, popAuthenticator);
			props.put("mail.smtp.host", "smtp.163.com");
			props.put("mail.smtp.auth", "true");
			Message newMessage = new MimeMessage(sendMailSession);
			newMessage.setFrom(new InternetAddress("muchuan69@163.com"));
			newMessage.setRecipient(Message.RecipientType.TO,
					new InternetAddress("yaya8657@163.com"));
			newMessage.setSubject("TEST");
			newMessage.setSentDate(new Date());
			newMessage.setText("你好,这是通过程序发的!");
			transport = sendMailSession.getTransport("smtp");
			transport.send(newMessage);
			System.out.println("邮件发送成功!");

		} catch (MessagingException m) {
			System.out.println(m.toString());
		}

	}
}

class PopupAuthenticator extends Authenticator {

	String username = null;//验证用户

	String password = null;

	public PopupAuthenticator(String user, String pass) {
		username = user;
		password = pass;

	}

	public PasswordAuthentication performCheck(String user, String pass) {
		username = user;
		password = pass;
		return getPasswordAuthentication();
	}

	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(username, password);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -