JAVA发送EMAIL的例子

 

import javax.mail.*;
02 import javax.mail.internet.MimeMessage;
03 import javax.mail.internet.InternetAddress;
04 import java.io.UnsupportedEncodingException;
05 import 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   */
14 public 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}
36 class PopupAuthenticator extends Authenticator {
37 public static final String mailuser= "wizzer"
38 public static final String password= "********" ;
39 public PasswordAuthentication getPasswordAuthentication() {
40 return new PasswordAuthentication(mailuser,password);
41}
42}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值