原文章地址:http://www.blogjava.net/wangfun/archive/2009/04/15/265748.html
以下三段代码是我的全部代码,朋友们如果想用,直接复制即可。
第一个类:MailSenderInfo.java


































































































第二个类:SimpleMailSender.java













































































































第三个类:MyAuthenticator.java



















下面给出使用上面三个类的代码:


















最后,给出朋友们几个注意的地方:
1、使用此代码你可以完成你的javamail的邮件发送功能。三个类缺一不可。
2、这三个类我打包是用的com.util.mail包,如果不喜欢,你可以自己改,但三个类文件必须在同一个包中
3、不要使用你刚刚注册过的邮箱在程序中发邮件,如果你的163邮箱是刚注册不久,那你就不要使用“smtp.163.com”。因为你发不出去。刚注册的邮箱是不会给你这种权限的,也就是你不能通过验证。要使用你经常用的邮箱,而且时间比较长的。
4、另一个问题就是mailInfo.setMailServerHost("smtp.163.com");与mailInfo.setFromAddress("han2000lei@163.com");这两句话。即如果你使用163smtp服务器,那么发送邮件地址就必须用163的邮箱,如果不的话,是不会发送成功的。
5、关于javamail验证错误的问题,网上的解释有很多,但我看见的只有一个。就是我的第三个类。你只要复制全了代码,我想是不会有问题的。
相关推荐
Java Mail 是一个用于处理电子邮件的开源API,它允许Java开发者在应用程序中实现发送、接收和操作邮件的功能。在这个实例中,我们将深入探讨如何使用Java Mail API来发送邮件,特别是涉及中文处理和HTML格式的邮件。...
提供的文件"发送邮件及邮件附件java代码实例(支持多附件_群发送).doc"和"java_mail_发送邮件代码.doc"可能包含了更详细的代码示例和具体实现过程,建议参考这些文档以获取完整的邮件发送和附件处理的代码。...
Java Mail 是一个用于处理电子邮件的开源API,它允许开发者通过编程方式发送、接收和操作邮件。这个API提供了广泛的协议支持,包括SMTP(简单邮件传输协议)用于发送邮件,POP3和IMAP4用于接收邮件。在Java Mail中,...
在你提供的压缩包文件中,包含了三个关键元素:activation.jar、mail.jar以及SendMail.java,这些都是Java Mail发邮件所需的基本组件。 `activation.jar` 是JavaBeans Activation Framework (JAF) 的一部分,它是...
Java Mail邮件发送是Java开发中常见的一项功能,用于在应用程序中发送电子邮件。Java Mail API提供了一个标准的接口,使得开发者可以方便地实现SMTP(简单邮件传输协议)和其他邮件协议的功能。下面将详细介绍Java ...
Java Mail 是一个用于处理电子邮件的开源API,它允许开发者通过编程方式发送、接收和管理邮件。这个源码可能包含了一套完整的解决方案,可以与多种邮局(如Gmail, Yahoo, Hotmail等)进行交互,并且支持单个收件人和...
要使用Java Mail发送QQ邮件,首先需要在QQ邮箱设置中开启“POP3/SMTP/IMAP”服务,并获取授权码。授权码是QQ邮箱为第三方应用提供的一种安全验证方式,不同于普通密码。 ### 3. 添加依赖 在Java项目中,我们需要...
要使用Java Mail发送邮件,首先需要添加相应的依赖库到项目中。对于Android项目,通常会通过Gradle来引入。 1. 添加依赖: 在项目的build.gradle文件中,添加以下依赖: ```groovy dependencies { ...
接着,我们创建一个`MimeMessage`实例,设置发件人、收件人、主题和正文,最后通过`Transport.send()`方法发送邮件。 Java Mail API还支持更复杂的功能,如添加附件、设置HTML格式的正文、使用多部分消息(MIME类型...
本文将详细介绍如何使用Java实现发送邮件的实例,并提供所需的库和步骤。 首先,JavaMail API是Java中用于处理邮件的核心库。在描述中提到的"jar包"很可能是JavaMail相关的依赖,例如`javax.mail`和`javax.mail-api...
`readme.txt` 文件可能是对整个邮件发送过程的简单说明或者是一些注意事项,比如提醒开发者需要在自己的环境中替换SMTP服务器配置,或者如何处理可能出现的异常情况。 在实际开发中,需要注意邮箱服务商的不同可能...
在这个实例中,我们将探讨如何使用Java来发送电子邮件,重点在于SMTP(Simple Mail Transfer Protocol)服务的使用。 首先,我们需要理解JavaMail API,这是一个Java库,允许开发者创建、发送和接收电子邮件。...
### 发送邮件——Java代码简单实例 #### 一、引言 在当今信息化时代,电子邮件是一种非常重要的通信方式。在企业应用开发中,通过程序自动发送邮件也是一项常见需求。本篇文章将详细介绍如何使用JavaMail API来实现...
在Java编程中,发送带有附件的邮件是一项常见的任务,尤其在企业级应用或者自动化脚本中。这个场景通常涉及到JavaMail API的使用,一个强大的库,可以用来处理SMTP(简单邮件传输协议)邮件服务。接下来,我们将深入...
在`Mail_class.java`文件中,我们将实现以下四种类型的邮件发送: 1. **发送纯文本邮件**: 要发送纯文本邮件,你需要创建一个`Properties`对象来设置SMTP服务器的相关属性,然后通过`Session`对象初始化邮件会话...
Spring框架提供了一种优雅的方式来处理这个任务,它整合了JavaMailSender接口和JavaMail API,使得在Java应用程序中发送邮件变得更加简单。让我们深入探讨这个主题。 首先,JavaMail API是Java用来处理邮件收发的...
下面是一个简单的Java邮件发送示例,展示如何使用JavaMail API发送邮件: ```java import javax.mail.*; import javax.mail.internet.*; public class SimpleJavaMail { public static void main(String[] args)...
在这个实例中,我们将深入探讨如何使用Java Mail API发送邮件,以及在不同环境下(如SSH框架和Servlet)的应用。 首先,我们要了解Java Mail API的基本概念。JavaMail API是由Sun Microsystems开发的一套用于处理...
以下是一个简单的示例代码,展示如何使用Java发送邮件: ```java import javax.mail.*; import javax.mail.internet.*; public class EmailSender { public static void main(String[] args) throws Exception { ...
本文将详细讲解如何使用Java实现这个功能,主要基于`javax.mail`库来创建一个简单的邮件发送程序。 首先,我们需要了解`javax.mail` API。这个库提供了丰富的接口和类,用于构建邮件发送的功能。为了发送邮件,我们...