Java mail runnable jar未运行
我正在开发一个监控程序,定期发送电子邮件。 一切都很顺利,直到我试着把它做成一个可以运行的罐子。 邮件部分在eclipse中运行良好,我能够发送电子邮件。但一旦我把它做成一个可运行的jar,程序就不会发送电子邮件Java mail runnable jar未运行,java,eclipse,email,executable-jar,Java,Eclipse,Email,Executable Jar,我正在开发一个监控程序,定期发送电子邮件。 一切都很顺利,直到我试着把它做成一个可以运行的罐子。 邮件部分在eclipse中运行良好,我能够发送电子邮件。但一旦我把它做成一个可运行的jar,程序就不会发送电子邮件 DEBUG: setDebug: JavaMail version 1.4.2 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun M
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO jason-DesktopPC1
250-mx.google.com at your service, [49.204.224.235]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFuaXRhbmkwMTI=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<chery012@gmail.com>
250 2.1.0 OK fk4sm25070066pab.23 - gsmtp
RCPT TO:<avinandan012@gmail.com>
250 2.1.5 OK fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: avinandan012@gmail.com
DATA
354 Go ahead fk4sm25070066pab.23 - gsmtp
Date: Thu, 19 Jun 2014 16:17:57 +0530 (IST)
From: chery012@gmail.com
To: avinandan012@gmail.com
Message-ID: <399262.0.1403174877546.JavaMail.example@gmail.com>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mail
.
250 2.0.0 OK 1403174885 fk4sm25070066pab.23 - gsmtp
QUIT
221 2.0.0 closing connection fk4sm25070066pab.23 - gsmtp
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO jason-DesktopPC1
250-mx.google.com at your service, [49.204.224.235]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFuaXRhbmkwMTI=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<chery012@gmail.com>
250 2.1.0 OK ih6sm8024528pbc.22 - gsmtp
RCPT TO:<avinandan012@gmail.com>
250 2.1.5 OK ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: avinandan012@gmail.com
DATA
354 Go ahead ih6sm8024528pbc.22 - gsmtp
Date: Thu, 19 Jun 2014 16:30:51 +0530 (IST)
From: chery012@gmail.com
To: avinandan012@gmail.com
Message-ID: <32535959.01403175651787.JavaMail.example@gmail.com>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mailQUIT
我做错了什么
package mailing;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class TestEmail
{
void addRecipients(Message.RecipientType type, Address[] addresses)throws MessagingException
{
}
public static void main(String [] args) throws Exception
{
final int port = 465;
final String host = "smtp.gmail.com";
final String from = "*****@gmail.com";
final String to = "********@gmail.com";
boolean auth = true;
final String username = "*******@gmail.com";
final String password = "**********";
boolean debug = true;
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.smtp.socketFactory.port","465");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.port","465");
Authenticator authenticator = null;
props.put("mail.smtp.auth", true);
authenticator = new Authenticator() {
PasswordAuthentication pa = new PasswordAuthentication(username, password);
@Override
public PasswordAuthentication getPasswordAuthentication() {
return pa;
}
};
Session session = Session.getInstance(props, authenticator);
session.setDebug(debug);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to.toString())};
message.setRecipients(Message.RecipientType.TO, address);
String subject="- Job Alert -";
message.setSubject(subject);
message.setSentDate(new Date());
String body="Hello you got a new mail";
message.setText(body);
Transport.send(message);
}
}
这是从eclipse运行时的eclipse控制台。
注意:最后关闭连接。
此代码发送电子邮件
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO jason-DesktopPC1
250-mx.google.com at your service, [49.204.224.235]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFuaXRhbmkwMTI=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<chery012@gmail.com>
250 2.1.0 OK fk4sm25070066pab.23 - gsmtp
RCPT TO:<avinandan012@gmail.com>
250 2.1.5 OK fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: avinandan012@gmail.com
DATA
354 Go ahead fk4sm25070066pab.23 - gsmtp
Date: Thu, 19 Jun 2014 16:17:57 +0530 (IST)
From: chery012@gmail.com
To: avinandan012@gmail.com
Message-ID: <399262.0.1403174877546.JavaMail.example@gmail.com>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mail
.
250 2.0.0 OK 1403174885 fk4sm25070066pab.23 - gsmtp
QUIT
221 2.0.0 closing connection fk4sm25070066pab.23 - gsmtp
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO jason-DesktopPC1
250-mx.google.com at your service, [49.204.224.235]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFuaXRhbmkwMTI=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<chery012@gmail.com>
250 2.1.0 OK ih6sm8024528pbc.22 - gsmtp
RCPT TO:<avinandan012@gmail.com>
250 2.1.5 OK ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: avinandan012@gmail.com
DATA
354 Go ahead ih6sm8024528pbc.22 - gsmtp
Date: Thu, 19 Jun 2014 16:30:51 +0530 (IST)
From: chery012@gmail.com
To: avinandan012@gmail.com
Message-ID: <32535959.01403175651787.JavaMail.example@gmail.com>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mailQUIT
DEBUG:setDebug:JavaMail版本1.4.2
调试:getProvider()返回javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,sun Microsystems,Inc]
调试SMTP:useEhlo true,useAuth true
调试SMTP:useEhlo true,useAuth true
调试SMTP:尝试连接到主机“SMTP.gmail.com”,端口465,isSSL false
220 mx.google.com ESMTP fk4sm25070066pab.23-gsmtp
调试SMTP:已连接到主机“SMTP.gmail.com”,端口:465
EHLO jason-1
250-mx.google.com为您服务,[49.204.224.235]
250号35882577
250-8比特
250-AUTH登录普通XOAUTH XOAUTH2普通CLIENTTOKEN
250-增强状态码
250分块
调试SMTP:找到扩展名“大小”,参数“35882577”
调试SMTP:找到扩展名“8BITMIME”,参数“”
调试SMTP:找到扩展名“AUTH”,arg“LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN”
调试SMTP:找到扩展名“ENHANCEDSTATUSCODES”,arg“”
调试SMTP:找到扩展名“分块”,arg“”
调试SMTP:尝试进行身份验证
调试SMTP:检查机制:登录普通摘要-MD5
身份验证登录
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFAXRHBMKWMTI=
235 2.7.0接受
调试SMTP:use8bit false
邮寄地址:
250 2.1.0正常fk4sm25070066pab.23-gsmtp
RCPT至:
250 2.1.5正常fk4sm25070066pab.23-gsmtp
调试SMTP:已验证的地址
调试SMTP:avinandan012@gmail.com
资料
354继续fk4sm25070066pab.23-gsmtp
日期:2014年6月19日星期四16:17:57+0530(IST)
发件人:chery012@gmail.com
致:avinandan012@gmail.com
消息ID:
主题:-工作警报-
MIME版本:1.0
内容类型:文本/纯文本;字符集=美国ascii码
内容传输编码:7bit
你好,你收到新邮件了吗
.
250 2.0.0正常1403174885 fk4sm25070066pab.23-gsmtp
退出
221 2.0.0闭合连接fk4sm25070066pab.23-gsmtp
这来自Win7 cmd,使用>java-jar EmailTest.jar
注意:节目永不停止。没有关闭连接。
这个罐子不发送电子邮件
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO jason-DesktopPC1
250-mx.google.com at your service, [49.204.224.235]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFuaXRhbmkwMTI=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<chery012@gmail.com>
250 2.1.0 OK fk4sm25070066pab.23 - gsmtp
RCPT TO:<avinandan012@gmail.com>
250 2.1.5 OK fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: avinandan012@gmail.com
DATA
354 Go ahead fk4sm25070066pab.23 - gsmtp
Date: Thu, 19 Jun 2014 16:17:57 +0530 (IST)
From: chery012@gmail.com
To: avinandan012@gmail.com
Message-ID: <399262.0.1403174877546.JavaMail.example@gmail.com>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mail
.
250 2.0.0 OK 1403174885 fk4sm25070066pab.23 - gsmtp
QUIT
221 2.0.0 closing connection fk4sm25070066pab.23 - gsmtp
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.google.com ESMTP ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO jason-DesktopPC1
250-mx.google.com at your service, [49.204.224.235]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250 CHUNKING
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5
AUTH LOGIN
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFuaXRhbmkwMTI=
235 2.7.0 Accepted
DEBUG SMTP: use8bit false
MAIL FROM:<chery012@gmail.com>
250 2.1.0 OK ih6sm8024528pbc.22 - gsmtp
RCPT TO:<avinandan012@gmail.com>
250 2.1.5 OK ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: avinandan012@gmail.com
DATA
354 Go ahead ih6sm8024528pbc.22 - gsmtp
Date: Thu, 19 Jun 2014 16:30:51 +0530 (IST)
From: chery012@gmail.com
To: avinandan012@gmail.com
Message-ID: <32535959.01403175651787.JavaMail.example@gmail.com>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mailQUIT
DEBUG:setDebug:JavaMail版本1.4ea
调试:getProvider()返回javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,sun Microsystems,Inc]
调试SMTP:useEhlo true,useAuth true
调试SMTP:useEhlo true,useAuth true
调试SMTP:尝试连接到主机“SMTP.gmail.com”,端口465,isSSL false
220 mx.google.com ESMTP ih6sm8024528pbc.22-gsmtp
调试SMTP:已连接到主机“SMTP.gmail.com”,端口:465
EHLO jason-1
250-mx.google.com为您服务,[49.204.224.235]
250号35882577
250-8比特
250-AUTH登录普通XOAUTH XOAUTH2普通CLIENTTOKEN
250-增强状态码
250分块
调试SMTP:找到扩展名“大小”,参数“35882577”
调试SMTP:找到扩展名“8BITMIME”,参数“”
调试SMTP:找到扩展名“AUTH”,arg“LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN”
调试SMTP:找到扩展名“ENHANCEDSTATUSCODES”,arg“”
调试SMTP:找到扩展名“分块”,arg“”
调试SMTP:尝试进行身份验证
调试SMTP:检查机制:登录普通摘要-MD5
身份验证登录
334 VXNlcm5hbWU6
Y2hlcnkwMTJAZ21haWwuY29t
334 UGFzc3dvcmQ6
VGFAXRHBMKWMTI=
235 2.7.0接受
调试SMTP:use8bit false
邮寄地址:
250 2.1.0正常ih6sm8024528pbc.22-gsmtp
RCPT至:
250 2.1.5正常ih6sm8024528pbc.22-gsmtp
调试SMTP:已验证的地址
调试SMTP:avinandan012@gmail.com
资料
354继续ih6sm8024528pbc.22-gsmtp
日期:2014年6月19日星期四16:30:51+0530(IST)
发件人:chery012@gmail.com
致:avinandan012@gmail.com
消息ID:
主题:-工作警报-
MIME版本:1.0
内容类型:文本/纯文本;字符集=美国ascii码
内容传输编码:7bit
你好,你有新邮件吗
我不确定这是否有效,请尝试以下代码:
public boolean sendMail(final String senderEmail, final String password, String recipientEmail, String ccEmail, String bccEmail) {
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "25");
Session session = Session.getInstance(props, null);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(senderEmail));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail));
if (ccEmail.length() > 0) {
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(ccEmail));
}
if(bccEmail.length() > 0){
message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bccEmail));
}
message.setSubject(this.subject);
message.setSentDate(new Date());
message.setText(this.textMessage, "utf-8");
SMTPTransport t = (SMTPTransport) session.getTransport("smtps");
t.connect("smtp.gmail.com", senderEmail, password);
t.sendMessage(message, message.getAllRecipients());
t.close();
System.out.println("Message sent successfully to '" + recipientEmail + "; " + ccEmail + "'.");
return true;
} catch (MessagingException e) {
System.out.println("Message not sent to '" + recipientEmail + "; " + ccEmail + "'.");
e.printStackTrace();
return false;
}
}
帮自己一个忙-从你的帖子中删除emailaddress密码组合…并更改密码,谢谢你们。非常心烦意乱,没有注意到。您正在使用com.sun.mail.smtp.SMTPTransport类吗?这段代码也可以在IDE中工作,但在打包为可运行jaryes时会引发异常我在线程“main”java.lang.NoSuchFieldError中使用C:\Users\jason\Desktop>java-jar EmailTest1.jar异常:atBOL位于com.sun.mail.smtp.SMTPOutputStream.EnsureABOL(SMTPOutputStream.java:107)在com.sun.mail.SMTPTransport.finishData(SMTPTransport.java:1472)在com.sun.mail.SMTPTransport.sendMessage(SMTPTransport.java:738)在mail.TestEmail.sendMail(TestEmail.java:49)在mail.TestEmail.main(TestEmail.java:68)可能是您问题的解决方案。问题解决了!手动编译文件并将库打包到jar解决了这个问题。不知道出了什么问题。奇怪的