Je développe un programme de surveillance, qui envoie des courriels périodiques. Tout s'est bien passé jusqu'à ce que j'essaie d'en faire un pot runnable. La partie mail fonctionne correctement en eclipse et je peux envoyer un email. Mais dès que j'en fais un pot runnable, le programme n'envoie jamais d'email.Le courrier exécutable Java jar ne fonctionne pas
Qu'est-ce que je fais mal?
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);
}
}
Il s'agit d'une console eclipse lorsqu'elle est exécutée à partir d'eclipse. Remarque: fermeture de la connexion à la fin. Ce code envoie un courrier électronique.
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:<[email protected]>
250 2.1.0 OK fk4sm25070066pab.23 - gsmtp
RCPT TO:<[email protected]>
250 2.1.5 OK fk4sm25070066pab.23 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 Go ahead fk4sm25070066pab.23 - gsmtp
Date: Thu, 19 Jun 2014 16:17:57 +0530 (IST)
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
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
Ceci est de Win7 cmd en utilisant> java -jar EmailTest.jar Avis: Le programme ne se ferme jamais. Pas de connexion de fermeture. Ce pot n'envoie pas d'e-mail.
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:<[email protected]>
250 2.1.0 OK ih6sm8024528pbc.22 - gsmtp
RCPT TO:<[email protected]>
250 2.1.5 OK ih6sm8024528pbc.22 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 Go ahead ih6sm8024528pbc.22 - gsmtp
Date: Thu, 19 Jun 2014 16:30:51 +0530 (IST)
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: - Job Alert -
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hello you got a new mailQUIT
vous une faveur - supprimer le combo emailaddress mot de passe de votre poste. – Stultuske
... et changer le mot de passe dès que possible –
merci les deux. Était très distrait n'a pas remarqué. – avinandan012