这是正常发送邮件的日志信息
第一行和最后一行分别是连接和断开连接的日志信息
Connected to the target VM, address: '127.0.0.1:62445', transport: 'socket'
DEBUG: JavaMail version 1.4.4
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.qq.com", port 465, isSSL true
220 newxmesmtplogicsvrsza7.qq.com XMail Esmtp QQ Mail Server.
DEBUG SMTP: connected to host "smtp.qq.com", port: 465
EHLO DESKTOP-BOMFV0O
250-newxmesmtplogicsvrsza7.qq.com
250-PIPELINING
250-SIZE 73400320
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "73400320"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "MAILCOMPRESS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
Mjc3NzQ1MTE1NEBxcS5jb20=
334 UGFzc3dvcmQ6
em5jeGl6eWJuYWFsZGZmZw==
235 Authentication successful
DEBUG SMTP: use8bit false
MAIL FROM:<2777xxxxx@qq.com>
250 OK.
RCPT TO:<109xxxx@qq.com>
250 OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: 1092xxxxx@qq.com
DATA
354 End data with <CR><LF>.<CR><LF>.
From: 27774xxxxxx@qq.com
To: 10924xxxx@qq.com
Message-ID: <1877940706.0.1617538523789.JavaMail.Mark@DESKTOP-BOMFV0O>
Subject: =?UTF-8?B?5YaN5p2l5LiA5Liq6YKu5Lu2?=
MIME-Version: 1.0
Content-Type: text/html;charset=utf-8
Content-Transfer-Encoding: quoted-printable
<a href=3D'https://www.baidu.com/'>=E6=B5=8B=E8=AF=95</a>
.
250 OK: queued as.
QUIT
221 Bye.
Disconnected from the target VM, address: '127.0.0.1:62445', transport: 'socket'
问题部分
这里使用到了单元测试,但是运行过之后只显示连接和断开的日志,没有打印发送日志更不用说发邮件了。
@Test
public void fayoujian() throws Exception{
String aimaddress = "1092xxxx@qq.com";
String title = "再来一个邮件";
String mtext = "<a href='https://www.baidu.com/'>测试</a>";
new Thread(){
@Override
public void run() {
super.run();
try {
SendQQMailUtil.Mailer(aimaddress,title,mtext);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
解决办法
也不知道哪里来的灵感,把这个代码放到main函数中运行就ok了,出现问题可能是因为junit单元测试随机的端口和main函数端口和qq邮箱的占用了--------------这里纯属个人见解,如果大神知道希望可以评论指点一下。