javamail

一文快速搞懂Springboot发送邮件操作

折月煮酒 提交于 2020-04-09 04:20:14
写在前面: 从2018年底开始学习SpringBoot,也用SpringBoot写过一些项目。这里对学习Springboot的一些知识总结记录一下。如果你也在学习SpringBoot,可以关注我,一起学习,一起进步。 目录 开通QQ邮箱的POP3/SMPT协议 发送邮件所需要的依赖文件 相关配置 发送邮件方法 开通QQ邮箱的POP3/SMPT协议 打开qq邮箱点击设置,之后点击账户,往下翻,如图。 找到POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务,点击开启,开启后会出现一个授权码,发送邮件时会用到。 发送邮件所需要的依赖文件 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> 相关配置 在application.properties配置文件中配置发邮件的相关配置: #设置字符集 spring.mail.default-encoding=UTF-8 spring.mail.host=smtp.qq.com #发送者的邮箱密码,这个密码不是QQ密码,而且上面的授权密码 spring.mail.password=发送者的邮箱密码 #端口 spring.mail

javamail使用SSL加密方式465端口

旧街凉风 提交于 2020-04-07 08:50:09
目前使用javamail发送邮件一般使用25端口,由于25端口是一个简单的邮件发送协议,所以经常会被滥用发送垃圾邮件,因此在一些服务器比如阿里云上会封禁该端口的使用. 解决的办法就是使用465端口:465端口是为SMTPS(SMTP-over-SSL)协议服务开放的,这是SMTP协议基于SSL安全协议之上的一种变种协议,它继承了SSL安全协议的非对称加密的高度安全可靠性,可防止邮件泄露。SMTPS和SMTP协议一样,也是用来发送邮件的,只是更安全些,防止邮件被黑客截取泄露,还可实现邮件发送者抗抵赖功能。防止发送者发送之后删除已发邮件,拒不承认发送过这样一份邮件。 package com.diannuo.util.emailUtil; import java.security.Security; import java.util.Date; import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport;

javax.mail.MessagingException: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 25;

落爺英雄遲暮 提交于 2020-03-25 18:42:09
问题 public void emailTest() { Properties properties=new Properties(); properties.put("mail.smtp.host", "email-smtp.us-east-1.amazonaws.com"); properties.put("mail.smtp.port", 587); properties.put("mail.debug", "true"); try{ Session session=Session.getInstance(properties); Message msg=new MimeMessage(session); msg.setFrom(new InternetAddress("test@gmail.com", "Test")); msg.setRecipient(RecipientType.TO, new InternetAddress("test@gmail.com", "Test")); msg.setSubject("Test Subject"); msg.setText(

javax.mail.MessagingException: Could not connect to SMTP host: email-smtp.us-east-1.amazonaws.com, port: 25;

℡╲_俬逩灬. 提交于 2020-03-25 18:42:02
问题 public void emailTest() { Properties properties=new Properties(); properties.put("mail.smtp.host", "email-smtp.us-east-1.amazonaws.com"); properties.put("mail.smtp.port", 587); properties.put("mail.debug", "true"); try{ Session session=Session.getInstance(properties); Message msg=new MimeMessage(session); msg.setFrom(new InternetAddress("test@gmail.com", "Test")); msg.setRecipient(RecipientType.TO, new InternetAddress("test@gmail.com", "Test")); msg.setSubject("Test Subject"); msg.setText(

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;

感情迁移 提交于 2020-03-23 06:28:34
问题 package jmail; import java.util.Date; import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class HtmlJavaSend { public void sendHtmlEmail(String host, String port, final String userName,

javaMail正确读取邮箱内容的方式

家住魔仙堡 提交于 2020-02-27 08:04:30
javaMail收邮件主要有两种协议,一种是pop3,一种是imap。这两种协议都可以用来收邮件,但是在其中的处理上是有区别的。pop3是不支持判断邮件是否为已读的,也就是说你不能直接从收件箱里面取到未读邮件,这需要自己进行判断,然而imap就提供了这样的功能,使用imap时可以很轻松的判断该邮件是否为已读或未读或其他。 此外收件箱中的每一封邮件都对应着一个MessageNumber,所以可以通过一个MessageNumber拿到对应的那封邮件。如:Message message = folder.getMessage(messageNumber);这样定时任务每次读邮箱邮件不用全量读了。 一、imap协议模式下读取 public static void readMail() { String protocol = "imap"; Properties props = new Properties(); props.setProperty("mail.transport.protocol", protocol); // 使用的协议(JavaMail规范要求) props.setProperty("mail.smtp.host", host); // 发件人的邮箱的 SMTP服务器地址 // 获取连接 Session session = Session.getInstance

javax.mail.AuthenticationFailedException in Android

♀尐吖头ヾ 提交于 2020-02-15 07:44:25
问题 I receive the below error message in my LogCat when trying to send an email from my Gmail account using JavaMail API. 11-09 11:04:14.385: W/System.err(18443): javax.mail.AuthenticationFailedException 11-09 11:04:14.385: W/System.err(18443): at javax.mail.Service.connect(Service.java:319) 11-09 11:04:14.385: W/System.err(18443): at javax.mail.Service.connect(Service.java:169) 11-09 11:04:14.385: W/System.err(18443): at javax.mail.Service.connect(Service.java:118) 11-09 11:04:14.385: W/System

Error: A JNI error has occurred (javax.mail.jar)

℡╲_俬逩灬. 提交于 2020-02-04 04:15:12
问题 I'm trying to read gmail messages using showmsg.java in the javamail sample package, and I keep getting this error when I run it. The program compiles fine though. Here's the error message: Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/internet/ParseException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class

JavaMail API : Username and Password not accepted (Gmail)

笑着哭i 提交于 2020-02-02 13:57:09
问题 I want to send email from my java application to gmail account I used the following code and javaMail API ,But Gmail not accepted username and password and exception thrown Can anybody help me how can I fix this issue? MailService.java public class MailService { String email; String content; public void sendMail(String email,String content) { this.email=email; this.content=content; // Recipient's email ID needs to be mentioned. String to = email; // Sender's email ID needs to be mentioned

JavaMail API : Username and Password not accepted (Gmail)

爱⌒轻易说出口 提交于 2020-02-02 13:56:09
问题 I want to send email from my java application to gmail account I used the following code and javaMail API ,But Gmail not accepted username and password and exception thrown Can anybody help me how can I fix this issue? MailService.java public class MailService { String email; String content; public void sendMail(String email,String content) { this.email=email; this.content=content; // Recipient's email ID needs to be mentioned. String to = email; // Sender's email ID needs to be mentioned