LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Java send mail error on Linux (https://www.linuxquestions.org/questions/linux-general-1/java-send-mail-error-on-linux-4175428960/)

sbutt 09-25-2012 10:42 AM

Java send mail error on Linux
 
Hi All,
I have a simple java program that sends an email.

Code:


public void sendMail(String content, String date) {

                try {
                        boolean debug = false;

                        // Set the host smtp address
                        Properties props = new Properties();
                        //props.put("mail.smtp.host", "localhost");

                        // create some properties and get the default Session
                        Session session = Session.getDefaultInstance(props, null);
                        session.setDebug(debug);

                        // create a message
                        javax.mail.Message msg = new MimeMessage(session);

                        // set the from and to address
                        InternetAddress addressFrom = new InternetAddress("sbutt@TTainment.de");
                        msg.setFrom(addressFrom);

                        InternetAddress[] addressTo = new InternetAddress[1];
                        addressTo[0] = new InternetAddress("sbutt@gmail.com");

                        msg.setRecipients(javax.mail.Message.RecipientType.TO, addressTo);

                        // Optional : You can also set your custom headers in the Email if
                        // you Want
                        // msg.addHeader("MyHeaderName", "myHeaderValue");

                        // Setting the Subject and Content Type

                        msg.setSubject("LCP Analysis Report :: " + date
                                        + " = Machine : "
                                        + InetAddress.getLocalHost().getHostName());
                        msg.setContent(content, "text/xml");
                        Transport.send(msg);
                        System.out.println("Email sent!!!");
                       

                } catch (UnknownHostException ex) {
                        ex.printStackTrace();
                } catch (MessagingException ex) {
                        ex.printStackTrace();
                }
        }

I get no exception and can see the "Email sent!!!" message after execution of the program.

But when i look into my linux "/var/log/mail.log", i see this error:

Code:


Sep 25 17:22:35 HH-Linux1 sm-mta[16301]: q8PFMNQe016301: from=<sbutt@TTainment.de>, size=3465, class=0, nrcpts=1, msgid=<15735326.0.1348586543811.JavaMail.root@HH-Linux1>, proto=ESMTP, daemon=MTA-v4, relay=root@localhost [127.0.0.1]
Sep 25 17:22:41 HH-Linux1 sm-mta[16324]: q8PFMNQe016301: to=<sbutt@gmail.com>, delay=00:00:06, xdelay=00:00:06, mailer=relay, pri=123465, relay=travel.TTainment.de, dsn=5.1.2, stat=Host unknown (Name server: travel.TTainment.de: host not found)
Sep 25 17:22:41 HH-Linux1 sm-mta[16324]: q8PFMNQe016301: q8PFMfQe016324: DSN: Host unknown (Name server: travel.TTainment.de: host not found)
Sep 25 17:22:41 HH-Linux1 sm-mta[16324]: q8PFMfQe016324: to=<sbutt@TTainment.de>, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30000, relay=travel.TTainment.de, dsn=5.1.2, stat=Host unknown (Name server: travel.TTainment.de: host not found)
Sep 25 17:22:41 HH-Linux1 sm-mta[16324]: q8PFMfQe016324: q8PFMfQf016324: return to sender: Host unknown (Name server: travel.TTainment.de: host not found)
Sep 25 17:22:41 HH-Linux1 sm-mta[16324]: q8PFMfQf016324: to=fuji, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

And email is also not received.

Could someone please suggest how, where and what to configure in Linux to have this problem resolved?

Thanks.

MensaWater 09-25-2012 11:26 AM

Your mail is trying to relay through a host named: travel.TTainment.de

However it is saying: travel.TTainment.de: host not found

That means your Linux server can't resolve the IP address for the domain.

What happens if you type "ping travel.TTainment.de", "host travel.TTainment.de" and "dig travel.TTainment.de"? Presumably you'll get similar errors.

Name resolution is done as specified by /etc/nsswitch.conf. What is in the line that starts with "hosts" in that file?

Does in include dns? If so what is in your /etc/resolv.conf? If it only says "files" what is in your /etc/hosts?

That is to say this isn't a mail failure but rather name resolution error.


All times are GMT -5. The time now is 10:08 PM.