Reputation: 51
My program is below:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Cygnet
*/
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
private String from;
private String to;
private String subject;
private String text;
public SendMail(String from, String to, String subject, String text){
this.from = from;
this.to = to;
this.subject = subject;
this.text = text;
System.out.println("your massege running here");
}
public void send(){
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.cygnet3.com");
props.put("mail.smtp.port", "8383");
Session mailSession = Session.getDefaultInstance(props);
Message simpleMessage = new MimeMessage(mailSession);
InternetAddress fromAddress = null;
InternetAddress toAddress = null;
try {
fromAddress = new InternetAddress(from);
toAddress = new InternetAddress(to);
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
simpleMessage.setFrom(fromAddress);
simpleMessage.setRecipient(RecipientType.TO, toAddress);
simpleMessage.setSubject(subject);
simpleMessage.setText(text);
Transport.send(simpleMessage);
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
String from = "[email protected]";
String to = "[email protected]";
String subject = "Hi server problem";
String message = "I could not find anything in the coding";
SendMail sendMail = new SendMail(from, to, subject, message);
sendMail.send();
System.out.println("Your massege is successfully sent");
}
}
I am getting the following exception:
run-main:
your massege running here
javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at SendMail.send(SendMail.java:58)
Your massege is successfully sent
at SendMail.main(SendMail.java:71)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 9 more
BUILD SUCCESSFUL (total time: 2 minutes 15 seconds)
Please help me, what mistake am I doing? I don't want to do username and password authentication, my port number and user ID is working fine.
Upvotes: 5
Views: 28676
Reputation: 128909
"Connection reset" means something unexpectedly closed the connection you were trying to establish. Maybe your SMTP server is expecting a secure connection (SSL or TLS). You could try connecting to smtp.cygnet3.com:8383 with telnet or netcat and see what you get. If you have openssl, you can check if it's a secure port with something like openssl s_client -connect smtp.cygnet3.com:8383
.
Edit: As Brian points out, port 8383 is an HTTP server. It looks like the web interface to a mail server. Try the standard port 25 (unsecure) or 587 (secure) instead.
Upvotes: 2
Reputation: 76918
There is no SMTP server running on that host at that port. You need a valid SMTP server.
It would appear there's a web server running on that port:
broach@roach-VirtualBox:~$ telnet smtp.cygnet3.com 8383
Trying 66.7.149.27...
Connected to cygnet3.com.
Escape character is '^]'.
HELO?
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Mon, 05 Sep 2011 05:35:35 GMT
Connection: close
Content-Length: 326
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Verb</h2>
<hr><p>HTTP Error 400. The request verb is invalid.</p>
</BODY></HTML>
Connection closed by foreign host.
Upvotes: 1