josefblgh
Messages postés2Date d'inscriptionmercredi 16 janvier 2008StatutMembreDernière intervention24 décembre 2008
-
22 déc. 2008 à 19:04
josefblgh
Messages postés2Date d'inscriptionmercredi 16 janvier 2008StatutMembreDernière intervention24 décembre 2008
-
24 déc. 2008 à 15:45
salut pour tous
mon problem c'est que j'essai d'envoyer un e-mail avec java mail mais j'arive pas
svp qlq1 peu m'aider?
mon code est le suivants:
import javax.mail.internet.*;
import javax.mail.*;
import java.util.*;
/**
*
* @author mostafa
*/
public class Premier_Msg {
String emailfrom = "[mailto:blghyoussef@yahoo.fr blghyoussef@yahoo.fr]";
String emailto = "[mailto:youssefblgh@yahoo.fr youssefblgh@yahoo.fr]";
String host = "smtp.mail.yahoo.fr";
// Récupére les propriétés du systéme
Properties props = System.getProperties();
// Spécification du serveur mail
public boolean Mail(){
boolean result=false;
props.put("mail.smtp.host", host);
// Récupère la session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// Définition du message
MimeMessage message = new MimeMessage(session);
try
{
//Spécification de l'expéditeur
message.setFrom(new InternetAddress(emailfrom));
//Spécification du destinataire
message.addRecipient(Message.RecipientType.TO, new InternetAddress(emailto));
//Sujet du message
message.setSubject("Premier mail");
//Texte du message
message.setText("Mon Premier mail");
init:
deps-jar:
compile-single:
run-single:
DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.fr", port 25, isSSL false
220 smtp105.mail.ukl.yahoo.com ESMTP
DEBUG SMTP: connected to host "smtp.mail.yahoo.fr", port: 25
EHLO dechraoui
250-smtp105.mail.ukl.yahoo.com
250-AUTH LOGIN PLAIN XYMCOOKIE
250-PIPELINING
250 8BITMIME
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XYMCOOKIE"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<
[mailto:blghyoussef@yahoo.fr
blghyoussef@yahoo.fr
]
>
530 authentication required - "for help go to
http://help.yahoo.com/help/us/mail/pop/pop-11.html "
DEBUG SMTP: got response code 530, with response: 530 authentication required - "for help go to
http://help.yahoo.com/help/us/mail/pop/pop-11.html "
RSET
DEBUG SMTP: exception reading response: java.net.SocketException: Software caused connection abort: recv failed
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Software caused connection abort: recv failed
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1611)
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1480)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at Premier_Msg.Mail(Premier_Msg.java:46)
at Premier_Msg.main(Premier_Msg.java:57)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:88)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1589)
... 8 more
QUIT
javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Software caused connection abort: socket write error
false
BUILD SUCCESSFUL (total time: 5 seconds)
public void setFrom(String from) {
this.from = from;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getSmtpServ() {
return smtpServ;
}
public void setSmtpServ(String smtpServ) {
this.smtpServ = smtpServ;
}
public int sendMail(){
try
{
Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put("mail.transport.protocol", "smtp" );
props.put("mail.smtp.starttls.enable","true" );
props.put("mail.smtp.host",smtpServ);
props.put("mail.smtp.auth", "true" );
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(message);
// -- Set some other header information --
msg.setHeader("MyMail", "Mr. XYZ" );
msg.setSentDate(new Date());
// -- Send the message --
Transport.send(msg);
System.out.println("Message sent to"+to+" OK." );
return 0;
}
catch (Exception ex)
{
ex.printStackTrace();
System.out.println("Exception "+ex);
return -1;
}
}
// Also include an inner class that is used for authentication purposes
private class SMTPAuthenticator extends javax.mail.Authenticator {
@Override
public PasswordAuthentication getPasswordAuthentication() {
String username = youracount@gmail.com; // specify your email id here (sender's email id)
String password =yourpassword@gmail.com; // specify your password here
return new PasswordAuthentication(username, password);
}
}
}
et pour l'utilise voila
Mail oMail =new Mail();
oMail.setTo(To_email);
oMail.setMessage("yello world" );