<pre>
Hi all,
I'm new to Javamail concept and i got the following exceptions when i tried to send a simple mail.
First exception is :
using java Could not connect to SMTP host: smtp.gmail.com, port: 25;
Second Exception is :
java.net.Socket Exception: Software caused connection abort: connect
i'm using Eudora as my mail client and its working fine.
what could be the problem with port.
Also,
Does a mail client should necessarily exist on the local machine to send mail thru java?
My code is like this:
import java.util.Prope rties;
import javax.mail.*;
import javax.mail.inte rnet.*;
public class SendMail
{
public static void main(String[] args)
{
if(args.length! =3)
{
System.out.prin tln("Usage: SendMail SMTPHost ToAddress FromAddress");
System.exit(1);
}
String smtpHost = args[0];
String to = args[1];
String from = args[2];
Properties props = System.getPrope rties();
props.put("mail .smtp.host",smt pHost);
props.put("mail .smtp.port","46 5");
try{
Session session = Session.getDefa ultInstance(pro ps, null);
MimeMessage message = new MimeMessage(ses sion);
message.setText ("Hi from the J2EE in 21 Days authors");
message.setSubj ect("Hi!");
message.setFrom (new InternetAddress (from));
message.addReci pient(Message.R ecipientType.TO , new InternetAddress (to));
Transport.send( message);
System.out.prin tln("Message Sent");
}
catch(Messaging Exception me)
{
System.err.prin tln("Messaging Exception : "+me.getMessage ());
}
}
}
Please help me ............!
</pre>
Hi all,
I'm new to Javamail concept and i got the following exceptions when i tried to send a simple mail.
First exception is :
using java Could not connect to SMTP host: smtp.gmail.com, port: 25;
Second Exception is :
java.net.Socket Exception: Software caused connection abort: connect
i'm using Eudora as my mail client and its working fine.
what could be the problem with port.
Also,
Does a mail client should necessarily exist on the local machine to send mail thru java?
My code is like this:
import java.util.Prope rties;
import javax.mail.*;
import javax.mail.inte rnet.*;
public class SendMail
{
public static void main(String[] args)
{
if(args.length! =3)
{
System.out.prin tln("Usage: SendMail SMTPHost ToAddress FromAddress");
System.exit(1);
}
String smtpHost = args[0];
String to = args[1];
String from = args[2];
Properties props = System.getPrope rties();
props.put("mail .smtp.host",smt pHost);
props.put("mail .smtp.port","46 5");
try{
Session session = Session.getDefa ultInstance(pro ps, null);
MimeMessage message = new MimeMessage(ses sion);
message.setText ("Hi from the J2EE in 21 Days authors");
message.setSubj ect("Hi!");
message.setFrom (new InternetAddress (from));
message.addReci pient(Message.R ecipientType.TO , new InternetAddress (to));
Transport.send( message);
System.out.prin tln("Message Sent");
}
catch(Messaging Exception me)
{
System.err.prin tln("Messaging Exception : "+me.getMessage ());
}
}
}
Please help me ............!
</pre>
Comment