Java实现QQ邮件发送(JavaMail)(Maven版)
发布日期:2021-06-29 15:03:07 浏览次数:3 分类:技术文章

本文共 1322 字,大约阅读时间需要 4 分钟。

一、邮箱设置

1、登陆邮箱后,进入设置,开启POP3/SMTPQQ邮箱为例

在这里插入图片描述

在这里插入图片描述

二、创建工程,添加依赖

在这里插入图片描述

在这里插入图片描述

在pom.xml当中添加依赖

4.0.0
com.itzheng
JavaMailDemo
0.0.1-SNAPSHOT
javax.mail
mail
1.4.4
junit
junit
4.11
org.springframework
spring-context-support
4.2.4.RELEASE

三、编写发送Email类

在这里插入图片描述

编写spring配置文件
创建applicationContext_mail.xml文件,copy文件头约束后,添加下面代码

true
true

在这里插入图片描述

四、发送邮箱

package com.itzheng.demo;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestJavaMail {
@Test public void testMail() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext-mail.xml"); TestSend ts = (TestSend) ac.getBean("testSend"); ts.sendMail(); }}

转载地址:https://code100.blog.csdn.net/article/details/111434344 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Java 实现定时任务(Quartz 框架)定时执行某个任务(Maven版)
下一篇:Android快速入门 基础知识,系统架构(快速开发第一个安卓应用程序)

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月25日 23时21分52秒