March 19, 2024, 02:44:36 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Java send mail error on Linux  (Read 8695 times)

Offline sbutt

  • New Member
  • Posts: 1
Java send mail error on Linux
« on: September 25, 2012, 03:45:29 PM »
Hi All,
       I have a simple java program that sends an email.

Code: [Select]

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: [Select]

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.