一种优秀的邮件发送工具包
类别: JSP教程
你是不是还在手工使用JavaMail API开发邮件程序?来看看这个工具吧,发送邮件只需要几行代码就可以搞惦!
// create a new Smtp instance providing hostname of SMTP serverSmtp smtp = new Smtp("smtp.myserver.com");//smtp.login(user,password);// create and address the e-mail. message EmailMessage message = new EmailMessage(); message.setTo("mjones@myserver.com"); message.setFrom("jsmith@myserver.com"); message.setSubject("Meeting today at 8"); message setBody("see you then"); // connect to SMTP server and send email messagesmtp.send(message);// disconnect from SMTP serversmtp.disconnect();
添加一个附件:
Attachment a = new Attachment(new File("/usr/home/report.doc"));message.addAttachment(a);
发送HTML格式的邮件:
message.setContentType("text/html");
怎么样,简单吧!这个包中还包括POP3、FTP、IMAP4等使用工具。
// create a new Smtp instance providing hostname of SMTP serverSmtp smtp = new Smtp("smtp.myserver.com");//smtp.login(user,password);// create and address the e-mail. message EmailMessage message = new EmailMessage(); message.setTo("mjones@myserver.com"); message.setFrom("jsmith@myserver.com"); message.setSubject("Meeting today at 8"); message setBody("see you then"); // connect to SMTP server and send email messagesmtp.send(message);// disconnect from SMTP serversmtp.disconnect();
添加一个附件:
Attachment a = new Attachment(new File("/usr/home/report.doc"));message.addAttachment(a);
发送HTML格式的邮件:
message.setContentType("text/html");
怎么样,简单吧!这个包中还包括POP3、FTP、IMAP4等使用工具。
-= 资 源 教 程 =-
文 章 搜 索