[JavaMal] SMTPSendFailedException lors de l'envoie de courier
bonjour
j'ai essayé d'envoyé un email à travers ce code au dessous ça fonctionnait mais quand j'ai changé de fournisseur d'accès il m'a causé plusieurs erreurs malgré que j'ai tenté de le modifier pour fonctionner mais rien ne change
voilà le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| package envoiemail;
import javax.mail.internet.*;
import javax.mail.*;
import java.util.*;
public class Test {
public static void main (String[] args) throws Exception {
String host = "smtp.gnet.tn";
String from = "address1@hotmail.fr ";
String to = "addresse2@hotmail.fr";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set the RFC 822 "From" header field using the
// value of the InternetAddress.getLocalAddress method.
message.setFrom(new InternetAddress(from));
// Add the given addresses to the specified recipient type.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set the "Subject" header field.
message.setSubject("salut!");
// Sets the given String as this part's content,
// with a MIME type of "text/plain".
message.setText("bienvenu dans notre groupe ");
// Send message
Transport.send(message);
System.out.println("Message Send.....");
}
} |
il m'a généré ces erreurs :
Code:
1 2 3 4 5 6 7 8 9 10
| Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 554 5.7.1 <address1@hotmail.fr>: Sender address rejected: Access denied
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
at javax.mail.Transport.send0(Transport.java:191)
at javax.mail.Transport.send(Transport.java:120)
at envoiemail.Test.main(Test.java:83)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds) |
merci de m'aidez à résoudre ce problème.
Envoi email avec classe jav + javaMail
j'ai essayé de m'authentifier au serveur mais le problème persiste
voilà le nouveau code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package miniprojet;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
public class Email {
public static void main (String[] args) throws Exception {
String smtpHost = "smtp.gnet.tn";
String from = "monemail@hotmail.fr";
String to = "email_destination@hotmail.fr";
String username = "monemail";
String password = "password_de_monemail";
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello");
message.setText("Hello World");
Transport tr = session.getTransport("smtp");
tr.connect(smtpHost, username, password);
message.saveChanges();
tr.send(message);
}
} |
il m'a généré ces erreurs je crois que c'est un problème de port 25 !
Code:
1 2 3 4 5 6 7 8 9 10
|
Exception in thread "main" javax.mail.AuthenticationFailedException: 535 5.7.8 Error: authentication failed: authentication failure
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at envoiemail.Test.main(Test.java:37)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds) |