LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-25-2012, 10:42 AM   #1
sbutt
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 09-25-2012, 11:26 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Linux base shell script with java which check the disk space and send mail to my id dhirendrs Linux - Newbie 2 06-14-2010 11:50 AM
call mail program like blat from java to send attachments naijaguy Linux - Software 1 05-04-2008 09:09 PM
with the linux proxi, backend pop3 mail client can not receive mail and send mail rubin823 Linux - Networking 0 12-21-2006 10:06 PM
need help JAVA send email to any mail server, yahoo, google.. etc... keikun_naruchan Programming 1 04-04-2006 02:18 AM
Java Mail fails to send a HTML mail eantoranz Programming 1 11-10-2004 01:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration