|
 |
j2ee thread: SMTP Host for Javamail Example
Message #1 by "sanjayhatwal" <sanjayhatwal@h...> on Wed, 12 Sep 2001 13:28:41
|
|
hotmail isnt an SMTP mail server, its an HTTP mail server. You need to get
yourself an SMTP provider. Examples to look for are (i think) yahoo. Usually
any provider who offers POP access to your box will also provide an SMTP
server.
chanoch
-----Original Message-----
From: sanjayhatwal [mailto:sanjayhatwal@h...]
Sent: 12 September 2001 14:29
To: Java 2 Enterprise Edition
Subject: [j2ee] SMTP Host for Javamail Example
Hello,
I have setup all the required API needed for Javamail.
I am trying to use this example file below which successfully compiles but
gives an error at runtime.
The example file: -
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
/**
* usage: sendmessage to from smtphost multipart
*
73 Appendix B: Examples Using the JavaMail API
Example: Sending a Message
JavaMail API Design Specification August 1998
* Send a simple text/plain message to the "to"
* address, from the "from" address, using the
* smtphost as the machine with the smtp server
* running.
*
* if multipart is "true" send a multipart message
* else if multipart is "false" send a text/plain
* message.
*/
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
// 74 Appendix B: Examples Using the JavaMail API
//Example: Sending a 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();
}
}
}
When I try to run this Application by passing arguments like :-
java sendmessage sanjayhatwal@h... sanjayhatwal@r...
mc1.law13.hotmail.com false
It gives me the following Error :
javax.mail.SendFailedExcaption : Sending Failed;
nested Exception is :
javax.mail.MessagingException : Could not connect to SMTP host:
mc1.law13.hotmail.com, port 25;
nested Exception is :
java.net.ConnectionException: Operation timed out : connect
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at sendmessage.main(sendmessage.java:80)
I have used the ping command on NT for hotmail.com and the SMTP host it
gave me a response saying (100% lost connection) but later it was alright
but still got the same error.
Please anyone could give a solution for it.
Thank you,
Sanjay Hatwal
|
|
 |