JavaMail Demo

package com.apptest.test;



import java.util.Properties;



import javax.mail.Authenticator;

import javax.mail.Message.RecipientType;

import javax.mail.MessagingException;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.AddressException;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;



public class JavaMailDemo {



	public static void main(String[] args) throws AddressException, MessagingException {

		Properties props = new Properties();

		props.setProperty("mail.host", "smtp.163.com");

		props.setProperty("mail.smtp.auth", "true");

		

		Authenticator authenticator = new Authenticator() {

			@Override

			protected PasswordAuthentication getPasswordAuthentication() {

				return new PasswordAuthentication("lvingw", "xxxxxxxxx");

			}

		};

		Session session = Session.getInstance(props, authenticator);

		

		MimeMessage msg = new MimeMessage(session);

		msg.setFrom(new InternetAddress("[email protected]"));

		msg.setRecipients(RecipientType.TO, "[email protected]");

		msg.addRecipients(RecipientType.CC, "[email protected]");

		

		msg.setContent("哈哈,javaMail send mail is OK????","text/html;charset=utf8");

		

		Transport.send(msg);

	}

}

  

你可能感兴趣的:(javamail)