⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 email3.java

📁 自己编写的邮件管理系统程序源代码,方便管理自己的邮件
💻 JAVA
字号:
package mail.test;import java.util.Date;import java.util.Properties;import javax.mail.Message;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;/** * 带身份验证的 email 发送程序 * * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2001</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Email3 {    int i;    public static void main(String[] argv) {        new Email3().test();    }    public void test()    {        for(i=0;i<20;i++)            send();    }    public void send() {      //收件人      String to = null;      //发件人      String from = null;      //主题      String subject = null;      //抄送人      String cc = null;      //暗抄送      String bcc = null;      // mail 主机      String mailhost = null;      // mail 内容      String content = null;      //MIME邮件对象      MimeMessage mimeMsg = null;      //邮件会话对象      Session session = null;      //************  不同之处    *************/      String user	 = null;      String password    = null;      try {        mailhost = "smtp.163.com";        from	 = "wyliufeng521@163.com";        to	 = "rhq_000@163.com";        subject	 = "哈批,这是第"+i+"封!";        content  = "这是你程序发的,哈批!";        user     = "wyliufeng521";        password = "19831218lf";       // Properties props = System.getProperties();  //获得系统属性        Properties   props   =   new   Properties();        props.put("mail.smtp.host", mailhost);      //设置SMTP主机        props.put("mail.smtp.auth","true");         //设置身份验证为真,若须身份验证则必须设为真        //获得邮件会话对象		//session = Session.getDefaultInstance(props,null);		//第二个参数为身份验证        session = Session.getDefaultInstance(props, new Email_Autherticatorbean( user, password ) );        //创建MIME邮件对象        mimeMsg = new MimeMessage( session );        //设置发信人        mimeMsg.setFrom(new InternetAddress( from ) );        //设置收信人        if(to!=null){           mimeMsg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( to ) );        }        //设置抄送人        if(cc!=null){           mimeMsg.setRecipients( Message.RecipientType.CC, InternetAddress.parse( cc ) );        }        //设置暗送人        if(bcc!=null){           mimeMsg.setRecipients( Message.RecipientType.BCC, InternetAddress.parse( bcc ) );        }        //设置邮件主题        mimeMsg.setSubject(subject,"GBK");        //设置邮件内容        mimeMsg.setText( content ,"GBK" );        //发送日期        mimeMsg.setSentDate(new Date());        //发送邮件        Transport transport = session.getTransport("smtp");        transport.connect(mailhost, user, password);        transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());   //     Transport.send( mimeMsg );        System.out.println( "email send!"+i);      } catch (Exception e) {        e.printStackTrace();      }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -