email

package cheapso.util;

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;

public class EmailUtil {

	private static String fromEmail = "[email protected]";
	private static String email_un = "554339501";
	private static String email_pw = "sunliall";
	private static String email_server_addr = "smtp.qq.com";
	private static int email_port = 25;

	public static void sendTo(String realname, String email, String content)
			throws Exception {
		Properties props = new Properties();
		props.setProperty("mail.smtp.auth", "true");
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", email_server_addr);
		Session session = Session.getInstance(props, new Authenticator() {
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(email_un, email_pw);
			}
		});
		// 显示调试信息
		// session.setDebug(true);
		Message msg = new MimeMessage(session);

		msg.setReplyTo(InternetAddress.parse(MimeUtility.encodeText("便宜搜")
				+ " <" + fromEmail + ">"));
		msg.setRecipients(RecipientType.TO, InternetAddress.parse(MimeUtility
				.encodeText(realname)
				+ " <" + email + ">"));
		msg.setSubject(MimeUtility.encodeText("找回密码邮箱通知"));
		msg.setFrom(new InternetAddress(MimeUtility.encodeText("便宜搜") + "<"
				+ fromEmail + ">"));

		msg.setContent(content, "text/html;charset=gbk");

		Transport transport = session.getTransport();

		Transport.send(msg);
	}

}

你可能感兴趣的:(html,qq)