Results 1 to 5 of 5
  1. #1
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Blog Entries
    1
    Rep Power
    0

    Default Java send mail error on Linux

    Hi All,
    I have a simple java program that sends an email.

    Java 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:

    Java 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.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Blog Entries
    1
    Rep Power
    0

    Default Re: Java send mail error on Linux

    Quote Originally Posted by Eranga View Post
    What's the exception that your code throw at line 41 or 43?
    My code throws no exception.

  4. #4
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: Java send mail error on Linux

    I don't see where you define the smtp server to use since the relevant code has been commented out!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default Re: Java send mail error on Linux

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. send mail via java without java mail API
    By majidvadoostan in forum Networking
    Replies: 2
    Last Post: 04-26-2011, 09:30 PM
  2. Send mail using a contactform
    By kroken in forum JavaServer Pages (JSP) and JSTL
    Replies: 18
    Last Post: 11-19-2010, 07:31 AM
  3. Replies: 2
    Last Post: 04-02-2009, 07:16 AM
  4. Help, Please!!! Can't Send Mail with SmtpClient
    By jfcup in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-07-2008, 12:46 PM
  5. Send a pic through mail, in java
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 07-25-2007, 02:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •