Bonjour,
je souhaite compiler une class d'envoi des email sous eclipse elle est basé sur javamail j'ai installé un srveur smtp et ajouter mail.jar et activation.jar voila le code source:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class sendmessage {
public static void main(String[] args) {
if (args.length != 4) {
System.out.println("usage: sendmessage <to> <from> <smtphost>" +"<true|false>");
System.exit(1);
}
boolean debug = false; // change to get more information
String msgText = "A body.\nthe second line.";
String msgText2 = "Another body.\nmore lines";
boolean sendmultipart =
Boolean.valueOf(args[3]).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host", args[2]);
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
try {
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(args[1]);
msg.setFrom(from);
InternetAddress[] address =
{new InternetAddress(args[0])};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("JavaMail APIs Test");
if (!sendmultipart) {
// send a plain text message
msg.setContent(msgText, "text/plain");
} else {
// send a multipart message
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
}
Transport.send(msg);
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
en compilant la class eclipse affiche le message d'erruer suivant :
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 551 User not local. We don't relay
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1294)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:635)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at sendmessage.main(sendmessage.java:51)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 551 User not local. We don't relay
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1145)
... 4 more
j'arrive pa a trouver la solution alor j'attend de l'aide de votre part et merci d'avance
