car
2016-08-10 22:50:10浏览 2633
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import junit.framework.TestCase;
public class JMail extends TestCase {
public void testName() throws AddressException, MessagingException {
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(""));
msg.setText("this is the first mail by java programing!");
msg.setSubject("SendMessageDemo1");
Transport transport = session.getTransport();
transport.connect("smtp.sina.com", 25, "", "");
transport.sendMessage(msg, new Address[] { new InternetAddress("") });
transport.close();
}
}