- 浏览: 307888 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (118)
- VS2008 (2)
- JAVA (34)
- AJAX (1)
- C# (1)
- Flex (16)
- FMS (6)
- SQLSERVER (1)
- ORACLE (1)
- Quartz (1)
- struts2 (1)
- java数据结构 (1)
- java设计模式 (3)
- JSF (0)
- web (2)
- jbpm4 (4)
- J2EE (1)
- webservice (2)
- javascript (8)
- spring (3)
- lucene (0)
- linux (9)
- ibatis (1)
- JPA (2)
- 外挂 (0)
- VB (0)
- Hibernate (1)
- OSGI (8)
- EXT (4)
- Maven (1)
- SpringSecurity (0)
- activiti (0)
- 项目开发 (0)
- 项目管理 (7)
- android (0)
- FFMPEG (1)
- C (2)
- eclipse (1)
最新评论
-
默默得守候在你的身边:
给力
java与Delphi写的dll交互 -
默默得守候在你的身边:
java与Delphi写的dll交互 -
fuguitong:
[url][url][url][url][url][url][ ...
doc转swf -
baidu_25402161:
到结束的时候一直 Can't delete processIn ...
一个请假单流程的实现(struts2.1.8+spring2.5+hibernate3集成jbpm4.3) -
lohaoo1:
nice!
java面包屑导航制作
MailInfo类:
//发送邮件的信息类 public class MailInfo { private String personal;// 姓名 private String subject;// 主题 private Date sentDate = new Date();// 发送时间 private List<String> toList = new ArrayList<String>();// 主送人集合 private List<String> ccList = new ArrayList<String>();// 抄送人集合 private List<String> bccList = new ArrayList<String>();// 密送人集合 private List<String> fileList = new ArrayList<String>();// 附件集合 private List<HtmlImage> imgList = new ArrayList<HtmlImage>();// 发送html所要用到的img图片集合 }
MailClient类:
package org.forever.javamail; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Properties; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.mail.Address; import javax.mail.BodyPart; import javax.mail.Flags; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; import javax.mail.Session; import javax.mail.Store; import javax.mail.Transport; import javax.mail.URLName; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeUtility; import javax.mail.util.ByteArrayDataSource; public class MailClient { private static final String CONTENT_ID = "Content-ID"; private static final String TEXT_PLAIN = "text/plain"; private static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; private static final String DEBUG = "debug"; private static final String FALSE = "false"; private static final String TRUE = "true"; private static final String POINT = "."; private static final String INBOX = "INBOX"; private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; private static final String POP3 = "pop3"; private static final String MAIL = "mail"; private static final String SMTP = "smtp"; private static final String AUTH = "auth"; private static final String HOST = "host"; private int pop3Port = 110; private String pop3Host; private String from;// 发件人邮件地址 private String userName;// 用户名 private String password;// 密码 private Session session;// 会话接口 private String savePath = "C:\\temp\\";// 附件保持路径 public static final int TEXT = 1;// 文本内容 public static final int HTML = 2;// html内容 private String smtpHost;// 域名 public MailClient(String userName, String password, String smtpHost, String pop3Host) { this.smtpHost = smtpHost; this.userName = userName; this.password = password; this.pop3Host = pop3Host; from = userName + "@" + smtpHost; Properties props = System.getProperties(); props.put(MAIL + POINT + SMTP + POINT + HOST, smtpHost); props.put(MAIL + POINT + SMTP + POINT + AUTH, TRUE); props.put(MAIL + POINT + DEBUG, FALSE); session = Session.getDefaultInstance(props, new EmailAuthenticator( userName, password)); } // 发送消息 public void sendMail(MailInfo mailInfo, int sendType) throws Exception { Message message = new MimeMessage(session); Address fromAddress = new InternetAddress(from, mailInfo.getPersonal()); message.setSubject(mailInfo.getSubject()); message.setSentDate(mailInfo.getSentDate()); message.setFrom(fromAddress); Multipart multipart = new MimeMultipart(); switch (sendType) { case TEXT: BodyPart textPart = new MimeBodyPart(); textPart.setContent(mailInfo.getContent(), "text/plain;charset=utf-8"); multipart.addBodyPart(textPart); break; case HTML: BodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(mailInfo.getContent(), "text/html;charset=utf-8"); multipart.addBodyPart(htmlPart); break; default: break; } for (String filePath : mailInfo.getFileList()) { File file = new File(filePath); if (!file.exists())continue; BodyPart attchPart = new MimeBodyPart(); DataSource source = new FileDataSource(file); attchPart.setDataHandler(new DataHandler(source)); attchPart.setFileName(MimeUtility.encodeText(file.getName())); multipart.addBodyPart(attchPart); } for (HtmlImage htmlImage : mailInfo.getImgList()) { String filePath = htmlImage.getFilePath(); File file = new File(filePath); if (!file.exists())continue; BodyPart imgPart = new MimeBodyPart(); imgPart.setDataHandler(new DataHandler( new ByteArrayDataSource(ImageUtil.imageToByteArray(filePath),APPLICATION_OCTET_STREAM) )); imgPart.setFileName(MimeUtility.encodeText(file.getName())); imgPart.setHeader(CONTENT_ID, "<"+htmlImage.getCid()+">"); multipart.addBodyPart(imgPart); } message.setContent(multipart); for (String bcc : mailInfo.getBccList()) { message.setRecipient(Message.RecipientType.BCC, new InternetAddress(bcc)); Transport.send(message); } System.out.println("send success....."); } public boolean isRead(Message message) throws Exception { boolean isRead = false; for (Flags.Flag flag : message.getFlags().getSystemFlags()) { if (flag == Flags.Flag.SEEN) { isRead = true; System.out.println("isRead=true......"); } } return isRead; } // 获取消息 public Message[] getMail() throws Exception { URLName urln = new URLName(POP3, pop3Host, pop3Port, null, userName, password); Store store = session.getStore(urln); store.connect(); Folder folder = store.getFolder(INBOX); folder.open(Folder.READ_ONLY); Message message[] = folder.getMessages(); return message; } // 清除所有邮件 public void clearAllMail() throws Exception { URLName urln = new URLName(POP3, pop3Host, pop3Port, null, userName, password); Store store = session.getStore(urln); store.connect(); Folder folder = store.getFolder(INBOX); folder.open(Folder.READ_WRITE); Message message[] = folder.getMessages(); for (Message item : message) { System.out.println("MegID: " + item.getMessageNumber() + " Title: " + item.getSubject() + "Flags: " + item.getFlags()); item.setFlag(Flags.Flag.DELETED, true); } folder.close(true); store.close(); } // 打印消息内容 public void printMessage(Message[] message) throws MessagingException, Exception, IOException { SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS); for (Message msg : message) { InternetAddress address = (InternetAddress) msg.getFrom()[0]; System.out.println("messageNumber:" + msg.getMessageNumber()); System.out.println("personal:" + address.getPersonal()); System.out.println("address:" + address.getAddress()); System.out.println("sentDate:" + sdf.format(msg.getSentDate())); System.out.println("status:" + isRead(msg)); System.out.println("subject:" + msg.getSubject()); Object content = msg.getContent(); if (content instanceof Multipart) { Multipart multipart = (Multipart) content; int count = multipart.getCount(); for (int i = 0; i < count; i++) { BodyPart bodyPart = multipart.getBodyPart(i); Object bodyContent = bodyPart.getContent(); String[] mimeType = bodyPart.getContentType().split(";"); System.out.println("type:" + bodyPart.getContentType()); if (APPLICATION_OCTET_STREAM.equals(mimeType[0])) { MimeBodyPart attchPart = (MimeBodyPart) bodyPart; String fileName = MimeUtility.decodeText(attchPart.getFileName()); System.out.println("fileName:" + fileName); InputStream in = attchPart.getInputStream(); FileUtil.saveFile(in, savePath,fileName); } else if (TEXT_PLAIN.equals(mimeType[0])) { System.out.println("content:" + bodyContent); } System.out.println("--------------------------------"); } } else { System.out.println(content); } System.out .println("*************************************************"); } } public String getSavePath() { return savePath; } public void setSavePath(String savePath) { this.savePath = savePath; } public int getPop3Port() { return pop3Port; } public void setPop3Port(int pop3Port) { this.pop3Port = pop3Port; } public String getPop3Host() { return pop3Host; } public void setPop3Host(String pop3Host) { this.pop3Host = pop3Host; } public String getFrom() { return from; } public void setFrom(String from) { this.from = from; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getSmtpHost() { return smtpHost; } public void setSmtpHost(String smtpHost) { this.smtpHost = smtpHost; } }
MailTest测试类:
package org.forever.javamail; import java.io.BufferedReader; import java.io.InputStreamReader; import org.junit.Test; public class MailTest { // 测试用户如下:chenjun,mqq,hds,yw // 测试局域网的发送情况 @Test public void testSendEmail_localhost() { // 假设发送人chenjun,主送人:mqq,抄送人:hds,密送人:yw MailClient cjClient = new MailClient("chenjun", "cj", "localhost", "localhost"); MailInfo cjMail = new MailInfo(); cjMail.setPersonal("陈均"); cjMail.setSubject("吃饭了"); cjMail.setContent("晚上9点,准时开饭"); cjMail.getToList().add("mqq@localhost"); cjMail.getCcList().add("hds@localhost"); cjMail.getBccList().add("yw@localhost"); try { cjClient.sendMail(cjMail, MailClient.TEXT); } catch (Exception e) { e.printStackTrace(); } } // 测试局域网所发邮件的信息是否已经收到 @Test public void testGetEmail_localhost() { MailClient mqqClient = new MailClient("mqq", "mqq", "localhost", "localhost"); MailClient hdsClient = new MailClient("hds", "hds", "localhost", "localhost"); MailClient ywClient = new MailClient("yw", "yw", "localhost", "localhost"); try { mqqClient.printMessage(mqqClient.getMail()); hdsClient.printMessage(hdsClient.getMail()); ywClient.printMessage(ywClient.getMail()); } catch (Exception e) { e.printStackTrace(); } } // 测试向abstractforever外网发送邮件 @Test public void testSendEmail_abstractforever() { // 假设发送人chenjun,主送人:mqq,抄送人:hds,//密送人:yw MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailInfo cjMail = new MailInfo(); cjMail.setPersonal("陈均"); cjMail.setSubject("吃饭了"); cjMail.setContent("晚上9点,准时开饭"); cjMail.getToList().add("mqq@abstractforever.gicp.net"); cjMail.getCcList().add("hds@abstractforever.gicp.net"); cjMail.getBccList().add("yw@abstractforever.gicp.net"); try { cjClient.sendMail(cjMail, MailClient.TEXT); } catch (Exception e) { e.printStackTrace(); } } // 测试所发邮件的信息是否已经收到 @Test public void testGetEmail_abstractforever() { MailClient mqqClient = new MailClient("mqq", "mqq", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailClient hdsClient = new MailClient("hds", "hds", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailClient ywClient = new MailClient("yw", "yw", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); try { mqqClient.printMessage(mqqClient.getMail()); hdsClient.printMessage(hdsClient.getMail()); ywClient.printMessage(ywClient.getMail()); cjClient.printMessage(cjClient.getMail()); } catch (Exception e) { e.printStackTrace(); } } // 测试清除邮件服务器的邮件 @Test public void testClearAllEmail_abstractforever() { MailClient mqqClient = new MailClient("mqq", "mqq", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailClient hdsClient = new MailClient("hds", "hds", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailClient ywClient = new MailClient("yw", "yw", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); try { mqqClient.clearAllMail(); hdsClient.clearAllMail(); ywClient.clearAllMail(); cjClient.clearAllMail(); } catch (Exception e) { e.printStackTrace(); } } // 测试向163外网发送邮件 @Test public void testSendEmail_163() { // 假设发送人chenjun,主送人:abstractforever,抄送人:abstractforever,密送人:abstractforever MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailInfo cjMail = new MailInfo(); cjMail.setPersonal("陈均"); cjMail.setSubject("吃饭了"); cjMail.setContent("晚上9点,准时开饭"); cjMail.getToList().add("abstractforever@163.com"); cjMail.getCcList().add("abstractforever@163.com"); cjMail.getBccList().add("abstractforever@163.com"); cjMail.getFileList().add("e:\\a.doc"); cjMail.getFileList().add("e:\\中文附件.doc"); try { cjClient.sendMail(cjMail, MailClient.TEXT); } catch (Exception e) { e.printStackTrace(); } } // 测试获取163邮件信息 @Test public void testGetEmail_163() { MailClient afClient = new MailClient("abstractforever", "*****", "smtp.163.com", "pop3.163.com"); try { afClient.printMessage(afClient.getMail()); } catch (Exception e) { e.printStackTrace(); } } // 测试清除163邮件信息 @Test public void testClearAllEmail_163() { MailClient cjClient = new MailClient("abstractforever", "*****", "smtp.163.com", "pop3.163.com"); try { cjClient.clearAllMail(); } catch (Exception e) { e.printStackTrace(); } } // 测试向qq外网发送邮件 @Test public void testSendEmail_qq() { // 假设发送人chenjun,主送人:396481925,抄送人:396481925,密送人:396481925 MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailInfo cjMail = new MailInfo(); cjMail.setPersonal("陈均"); cjMail.setSubject("吃饭了"); cjMail.setContent("晚上9点,准时开饭"); cjMail.getToList().add("396481925@qq.com"); cjMail.getCcList().add("396481925@qq.com"); cjMail.getBccList().add("396481925@qq.com"); try { cjClient.sendMail(cjMail, MailClient.TEXT); } catch (Exception e) { e.printStackTrace(); } } // 测试获取qq邮件信息 @Test public void testGetEmail_qq() { MailClient qqClient = new MailClient("396481925", "*****", "smtp.qq.com", "pop.qq.com"); try { qqClient.printMessage(qqClient.getMail()); } catch (Exception e) { e.printStackTrace(); } } // 测试清除qq邮件信息 @Test public void testClearAllEmail_qq() { MailClient cjClient = new MailClient("396481925", "*****", "smtp.qq.com", "pop.qq.com"); try { cjClient.clearAllMail(); } catch (Exception e) { e.printStackTrace(); } } // 测试向abstractforever外网发送邮件,带附件的 @Test public void testSendEmailAtt_abstractforever() { // 假设发送人chenjun,主送人:mqq,抄送人:hds,//密送人:yw MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailInfo cjMail = new MailInfo(); cjMail.setPersonal("陈均"); cjMail.setSubject("吃饭了"); cjMail.setContent("晚上9点,准时开饭"); cjMail.getToList().add("mqq@abstractforever.gicp.net"); cjMail.getFileList().add("e:\\a.doc"); cjMail.getFileList().add("e:\\中文附件.doc"); try { cjClient.sendMail(cjMail, MailClient.TEXT); } catch (Exception e) { e.printStackTrace(); } } // 测试向abstractforever外网获取邮件,带附件的 @Test public void testGetEmailAtt_abstractforever() { MailClient mqqClient = new MailClient("mqq", "mqq", "abstractforever.gicp.net", "abstractforever.gicp.net"); try { mqqClient.printMessage(mqqClient.getMail()); } catch (Exception e) { e.printStackTrace(); } } // 测试发送html内容,带图片 @Test public void testSendEmailHtml_163() { // 假设发送人chenjun,主送人:abstractforever,抄送人:abstractforever,密送人:abstractforever MailClient cjClient = new MailClient("chenjun", "cj", "abstractforever.gicp.net", "abstractforever.gicp.net"); MailInfo cjMail = new MailInfo(); cjMail.setPersonal("陈均"); cjMail.setSubject("吃饭了"); StringBuffer html = new StringBuffer(); String line = ""; try { BufferedReader in = new BufferedReader(new InputStreamReader( MailTest.class.getClassLoader().getResourceAsStream( "table.html"), "UTF-8")); while ((line = in.readLine()) != null) { html.append(line); } } catch (Exception e1) { e1.printStackTrace(); } System.out.println(html); cjMail.setContent(html.toString()); cjMail.getImgList().add(new HtmlImage("img_1", "e:\\a.jpg")); cjMail.getToList().add("abstractforever@163.com"); cjMail.getFileList().add("e:\\a.doc"); cjMail.getFileList().add("e:\\中文附件.doc"); try { cjClient.sendMail(cjMail, MailClient.HTML); } catch (Exception e) { e.printStackTrace(); } } }
评论
1 楼
命中注定1314
2012-07-25
请问下, 删除邮件的时候真的可以吗 ,我也是像你那样也写的,也设置了 folder.open(Folder.READ_WRITE);
删除的时候总报异常
javax.mail.IllegalWriteException: POP3 messages are read-only
请问知道是怎么回事吗? qq:576240289
删除的时候总报异常
javax.mail.IllegalWriteException: POP3 messages are read-only
请问知道是怎么回事吗? qq:576240289
发表评论
-
OSGI学习
2012-03-18 18:01 0http://www.blogjava.net/zhenyu3 ... -
OSGI学习笔记(七)
2012-03-17 23:58 1693SpringDM初步使用(二) 介绍哈官方的第二个例子 ... -
ubuntu10.04下nexus和maven的安装及配置
2012-03-14 16:14 2510前提要有jdk环境,官方下载nexus和maven,解压后创建 ... -
ubuntu10.04下eclipse的安装及配置
2012-03-14 00:01 1306从官方http://www.eclipse.org/downl ... -
Ubuntu10.04下配置java环境变量
2012-03-13 23:28 1066Ubuntu10.04默认安装了OpenJDK,但还是基于Su ... -
eclipse设置保护色
2012-03-16 09:22 9414eclipse操作界面默认颜色为白色。对于我们长期使 ... -
OSGI学习笔记(六)
2012-03-17 15:08 2754SpringDM初步使用(一) 官方地址http:// ... -
OSGI学习笔记(八)
2012-03-19 21:08 2301SpringDM初步使用(三) spring第三个例子 ... -
OSGI学习笔记(五)
2011-07-31 10:32 1585开放服务网关协议 (Open Services Gateway ... -
osgi学习笔记(三)
2011-07-16 22:43 1959OSGI实战书上讲了一个web登陆验证切换功能。表达了osgi ... -
word工具类
2011-03-15 09:19 1443package org.foreverframework ... -
命令模式--撤销恢复
2011-03-14 22:32 4985该例子来自阎宏提供的 ... -
java zip
2011-03-06 15:32 1215import java.io.BufferedInputStr ... -
doc转swf
2010-12-07 22:03 8540将doc转换成swf,然后显示在html页面上。 packa ... -
xloadtree的一个改造
2010-09-20 22:58 2568修改了xloadtree的部分源码以适合自己使用。 1.修改 ... -
java与Delphi写的dll交互
2010-09-05 22:27 6160有时候在项目开发的时候难免会和硬件提供的开发包接触,这些开发接 ... -
JAVA与DLL交互
2010-08-27 23:32 1945jna官网地址:https://jna.dev.java.ne ... -
office工具类
2010-07-31 14:17 2308将jcom.dll放入jdk的bin目录下,将jcom.jar ... -
启动多个tomcat
2010-04-22 09:13 1214想启动多个tomcat,只需修改conf/server.xml ... -
dos 删除指定日期前的文件
2010-04-19 22:47 3459@echo off&setlocal enablede ...
相关推荐
### JavaMail简易教程知识点详解 #### 一、JavaMail API简介 JavaMail API是一个用于读取、编写和发送电子邮件的标准扩展包。通过这个API,开发者能够构建类似Eudora、Pine或Microsoft Outlook这样的邮件用户代理...
通过这些步骤,就可以利用 JavaMail 实现强大的邮件功能,无论是发送简单的文本邮件,还是构建复杂的多附件、HTML 内容的邮件,都能轻松应对。同时,JavaMail 也提供了对不同邮件服务器和协议的良好兼容性,使其成为...
本篇文章将详细探讨JavaMail的简单使用,包括如何设置、配置以及实际发送邮件。 一、JavaMail的环境配置 在使用JavaMail之前,首先需要将其添加到项目的类路径中。这通常通过Maven或Gradle的依赖管理来实现。如果...
这个"javamail使用demo示例"是JavaMail官方提供的一个实例集合,旨在帮助开发者更好地理解和应用JavaMail库。下面我们将深入探讨JavaMail的核心概念、主要功能以及如何使用这些示例代码。 一、JavaMail核心概念 1....
本文将深入探讨JavaMail的核心概念、主要组件以及如何在实际项目中进行简单应用。 1. **JavaMail API概述** JavaMail API是Java平台上的一个开源库,由JavaMail项目维护,用于处理邮件服务。它包括了SMTP(Simple ...
JavaMail是一种在Java应用程序中发送和接收电子邮件的标准API,它为开发者提供了强大的功能,使得处理邮件变得简单而高效。在JavaMail中,我们主要利用 javax.mail 和 javax.mail.internet 这两个包中的类来实现邮件...
"Linux服务器报警—使用javamail"这个主题就涉及到了如何利用JavaMail API在Linux环境中实现自动发送邮件报警的功能。JavaMail是一个开源库,它允许开发者在Java应用中添加电子邮件功能,包括发送和接收邮件。 首先...
2. **SMTP协议**:JavaMail 使用简单邮件传输协议(SMTP)来发送邮件。通过SMTP服务器,程序能够将邮件路由到正确的收件人。 3. **POP3和IMAP协议**:对于邮件接收,JavaMail 提供了对邮局协议第三版(POP3)和...
根据提供的文件描述部分,JavaMail API不仅仅能够执行一些简单的邮件传输任务,它还能被用来构建功能丰富的邮件客户端应用,类似于Microsoft Outlook。这意味着,JavaMail API可以用来实现从创建邮件、添加附件、...
javamail例子——简单好用 可以直接发电子邮件 1.当工程是java EE 5的时候 在工程里面应该删除java EE 5里面相对应的 jar 路径在 第一个问题就是删除Java EE 5 Libraries/javaee.jar/mail。 第二个问题就是删除Java...
简易封装的javaMail 支持同时发送信息与附件,发件人,发件时间,主题,内容,附件等等 内涵详细的说明与测试使用方法
在提供的压缩包文件中,可能包含了一个简单的JavaMail使用示例。通过分析和学习这个例子,你可以更好地理解如何在实际项目中集成和使用JavaMail发送邮件。记得检查代码中的异常处理和错误日志,这对于调试和解决问题...
在JavaMail中,开发者可以利用SMTP(简单邮件传输协议)、POP3(邮局协议)和IMAP(因特网消息访问协议)等标准来与邮件服务器进行交互。为了使用JavaMail的功能,你需要在项目中包含相应的jar包。这些jar包通常包含...
JavaMail API是Java平台上用于处理电子邮件的一套标准API,它为...总之,JavaMail API和`javaMail.jar`是Java开发者处理电子邮件不可或缺的工具,它们提供了强大的功能,使得在程序中发送和接收邮件变得简单易行。
以下是一个简单的示例,展示了如何使用JavaMail发送邮件: ```java Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put(...
在使用JavaMail API时,开发者需要先创建一个`Session`实例,配置好邮件服务器的相关参数,然后可以创建`Message`对象,填充邮件内容,最后通过`Transport`发送邮件。对于接收邮件,JavaMail也提供了相应的API,可以...
在“javax.mail.jar”这个压缩包文件中,包含了 JavaMail API 的所有核心类和接口,开发者可以直接导入这个 JAR 文件到他们的项目中,以使用 JavaMail 提供的各种邮件服务功能。例如,`...
这个“简单javamail的实现(HelloWorld)”的教程将引导我们通过创建一个基础的JavaMail应用,这通常被称为“HelloWorld”示例,因为它标志着我们对JavaMail API的初步理解和使用。 JavaMail API 提供了广泛的类和...
### JavaMail简易教程知识点概述 #### 一、JavaMail API简介 JavaMail API是一个用于读取、编写和发送电子邮件的标准扩展包。它主要用于创建邮件用户代理(MUA)类型的程序,例如Eudora、Pine及Microsoft Outlook等。...