Отправка почты не работает и показывает исключение

Моя программа ниже:

/*
 * 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 = "sender@example.com";
            String to = "recipient@example.com";
            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");
        }        

    }

Я получаю следующее исключение:

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)

Пожалуйста, помогите мне, какую ошибку я делаю? Я не хочу делать имя пользователя и аутентификацию пароля, мой номер порта и идентификатор пользователя работают нормально.

5
задан Arjan 5 September 2011 в 05:38
поделиться