首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

JAVA发送EMAIL的例证

2013-07-11 
JAVA发送EMAIL的例子?import javax.mail.* 02import javax.mail.internet.MimeMessage 03import javax.m

JAVA发送EMAIL的例子

?

import javax.mail.*; 02import javax.mail.internet.MimeMessage; 03import javax.mail.internet.InternetAddress; 04import java.io.UnsupportedEncodingException; 05import java.util.Properties; 06? ?07/** 08? * Created by IntelliJ IDEA. 09? * User: Wizzer 10? * Date: 2010-12-29 11? * Time: 16:39:50 12? * To change this template use File | Settings | File Templates. 13? */14public class Mail { 15???? public static void main(String args[]) throws MessagingException, UnsupportedEncodingException { 16???? Properties props = new Properties(); 17???? props.put( "mail.smtp.host" , "smtp.qq.com" ); 18???? props.put( "mail.smtp.auth" , "true" ); 19???? PopupAuthenticator auth = new PopupAuthenticator();? 20???? Session session = Session.getInstance(props, auth); 21???? MimeMessage message = new MimeMessage(session); 22???? Address addressFrom = new InternetAddress(PopupAuthenticator.mailuser+ "@qq.com" , "George Bush" ); 23???? Address addressTo = new InternetAddress( "116****@qq.com" , "George Bush" ); //收件人 24???? message.setText( "邮件发送成功" ); 25???? message.setSubject( "Javamal最终测试" ); 26???? message.setFrom(addressFrom); 27???? message.addRecipient(Message.RecipientType.TO,addressTo); 28???? message.saveChanges(); 29???? Transport transport = session.getTransport( "smtp" ); 30???? transport.connect( "smtp.qq.com" , PopupAuthenticator.mailuser,PopupAuthenticator.password); 31???? transport.send(message); 32???? transport.close(); 33???? } 34? ?35} 36class PopupAuthenticator extends Authenticator { 37public static final String mailuser= "wizzer" ;? 38public static final String password= "********" ; 39public PasswordAuthentication getPasswordAuthentication() { 40return new PasswordAuthentication(mailuser,password); 41} 42}

热点排行