Hi

I have written a code for sending a mail, it was working fine before and now it hangs at tranport.send().

Can any one help, here my code
Inline Code Example Here

try {



            System.out.println("Sending Email initiated...");
            Properties properties = System.getProperties();
            properties.put("mail.smtp.auth", "false");
            properties.put("mail.smtp.starttls.enable", "true");
            properties.put("mail.smtp.host", _host);
            properties.put("mail.smtp.port", _port);
             properties.put("mail.smtp.connectiontimeout", "100000");
            properties.put("mail.smtp.timeout", "100000");
            Session session = Session.getInstance(properties,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(_emailfrom, "");
                        }
                    });
            MimeMessage message = new MimeMessage(session);
            log.debug("Sending Email from: " + _emailfrom);
            // System.out.println("Sending Email from: " + _emailfrom);
            // Set From: header field of the header.
            message.setFrom(new InternetAddress(_emailfrom));



            to_recep = _toreceipients.split(",");
            if (to_recep.length > 0) {

                for (int i = 0; i < to_recep.length; i++) {
                    message.addRecipient(Message.RecipientType.TO,
                            new InternetAddress(to_recep[i]));
                }
            }

            cc_recep = _ccreceipients.split(",");
            if (cc_recep.length > 0) {

                for (int i = 0; i < cc_recep.length; i++) {
                    if (cc_recep[i].length() > 2)
                        message.addRecipient(Message.RecipientType.CC,
                                new InternetAddress(cc_recep[i]));
                }
            }
            log.debug("Setting Subject & Content of Email");

            message.setSubject(MSG_SUBJECT + " " + getCurrentDate());
            message.setText(_message, "utf-8", "html");

            log.debug("Going to send an Email ....");
            // System.out.println("Going to send an Email ....");
            // Send message
            Transport.send(message);

            log.debug("Email send successfully....");
            // System.out.println("Email send successfully....");
        } catch (MessagingException mex) {
            mex.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
            log.debug(e.getMessage());
        }

yes it is working fine from my local system, and was working fine on server also but now it has started giving problem.
No exception is coming, i have set a timout for 1.6 min.

"now it has started giving problem" ...
this is a bit vague. Have you been able to reproduce the problem while debugging? is there logging? how do you know for sure where the code hangs? are you sure it's not your connection?

Hi
I have tested my code from local and it is working fine, i have placed loggers can it be a unix machine problem?

This article has been dead for over six months. Start a new discussion instead.