Problème de réception de mail avec java mail
Bonjour,
je souhaite executé 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:
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 56
| 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();
}
}
} |
et les arguments que je doit introduire dans eclipse sur open run dialog ensuite arguments et j'ai ecris les arguments en laissant un espace entre chacun
en executant la class, eclipse n'affiche aucune erreur et je recois aucun message par contre mon serveur smtp affiche (argosoft):
26/05/2008 20:20:29 - Requested SMTP connection from 127.0.0.1
26/05/2008 20:20:29 - ( 1) 220 ArGoSoft Mail Server Freeware, Version 1.8 (1.8.9.2)
26/05/2008 20:20:29 - ( 1) EHLO unicorni-dc5d36
26/05/2008 20:20:29 - ( 1) 250-Welcome [127.0.0.1], pleased to meet you
26/05/2008 20:20:29 - ( 1) 250-SIZE 5242880
26/05/2008 20:20:29 - ( 1) 250 HELP
26/05/2008 20:20:29 - ( 1) MAIL FROM:<khalil.osiris@hotmail.com>
26/05/2008 20:20:29 - ( 1) 250 Sender "khalil.osiris@hotmail.com" OK...
26/05/2008 20:20:29 - ( 1) RCPT TO:<khalil23nwa@yahoo.com>
26/05/2008 20:20:29 - ( 1) 250 Recipient "khalil23nwa@yahoo.com" OK...
26/05/2008 20:20:29 - ( 1) DATA
26/05/2008 20:20:29 - ( 1) 354 Enter mail, end with "." on a line by itself
26/05/2008 20:20:30 - Received 606 bytes
26/05/2008 20:20:30 - ( 1) 250 Message accepted for delivery.
26/05/2008 20:20:30 - ( 1) QUIT
26/05/2008 20:20:30 - ( 1) 221 Aba he
26/05/2008 20:20:30 - SMTP connection with 127.0.0.1 ended. ID=1