导包
| <dependency> |
| <groupId>javax.mail</groupId> |
| <artifactId>mail</artifactId> |
| <version>1.4.7</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>javax.activation</groupId> |
| <artifactId>activation</artifactId> |
| <version>1.1.1</version> |
| </dependency> |
编写程序
| |
| package com.Google; |
| |
| import com.sun.mail.util.MailSSLSocketFactory; |
| |
| import javax.imageio.spi.ImageInputStreamSpi; |
| import javax.mail.*; |
| import javax.mail.internet.InternetAddress; |
| import javax.mail.internet.MimeMessage; |
| import java.util.Properties; |
| |
| public class mailTest { |
| public static void main(String[] args) throws Exception { |
| Properties prop = new Properties(); |
| prop.setProperty("mail.host","stmp.qq.com"); |
| prop.setProperty("mail.transport.protocol","smtp"); |
| prop.setProperty("mail.smtp.auth","true"); |
| |
| |
| MailSSLSocketFactory sf = new MailSSLSocketFactory(); |
| sf.setTrustAllHosts(true); |
| prop.put("mail.smtp.ssl.enable","true"); |
| prop.put("mail.smtp.ssl.socketFactory",sf); |
| |
| |
| |
| Session session = Session.getDefaultInstance(prop, new Authenticator() { |
| @Override |
| protected PasswordAuthentication getPasswordAuthentication() { |
| |
| return new PasswordAuthentication("2034281740@qq.com", "授权码"); |
| } |
| }); |
| session.setDebug(true); |
| |
| |
| Transport transport = session.getTransport(); |
| |
| transport.connect("smtp.qq.com","2034281740@qq.com", "授权码"); |
| |
| MimeMessage message = new MimeMessage(session); |
| message.setFrom(new InternetAddress("2034281740@qq.com")); |
| message.setRecipient(Message.RecipientType.TO, new InternetAddress("2034281740@qq.com")); |
| message.setSubject("叫我靓仔"); |
| message.setContent("叼毛,叼毛","text/html;charset=UTF-8"); |
| |
| transport.sendMessage(message, message.getAllRecipients()); |
| |
| |
| |
| } |
| } |
| |
| |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术