• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaMail Problem at UNIX mail server

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is the code i use to send an email using JavaMail API

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;

public class Mailing {
/* This class allow send an email to a receipient
It need 4 input:
1. email of receipient
2. email of sender
3. title of the email
4. content of the mail
*/
public static String createMessage(String to, String from, String subject, String content, String host) throws Exception
{
String error = null;

try{
// Get system properties
Properties props = System.getProperties();

// Set the transport protocol format (SMTP)
//props.put("mail.transport.protocol", "SMTP");

// Setup mail server
props.put("mail.smtp.host", host);

// Get session
Session session = Session.getDefaultInstance(props, null);

// Define message
Message message = new MimeMessage(session);

// Set sagethe from address
message.setFrom(new InternetAddress(from));

// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));

// Set the subject
message.setSubject(subject);

// Set the content
message.setText(content);

// Send message
Transport.send(message);
}catch (Exception e)//Get exception and error message
{
error = e.getMessage();
}
return error;
}
}



The error i got is :
Error : Sending failed; nested exception
is: javax.mail.MessagingException: Unknown SMTP host:
<server name>; nested exception is:
java.net.UnknownHostException: <server name>


I did not face any problem in window but i got the error when i run in UNIX server
 
daniel ong
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'd found a solution for this problem.

this is the code i use:

try{

PrintStream out1;

SmtpClient send = new SmtpClient("smtp........com"); // create a mail client
send.from(emailVal); // email address of the sender
send.to(" "); // email address of the receiver

out1 = send.startMessage();

//Format of the email
out1.println("From: cct115c@motorola.com");
out1.println("To: cyo006c@motorola.com");
out1.println("Subject: " + subject);

out1.println(content);

out1.flush();
out1.close();
send.closeServer();
}
catch (Exception e) {
errorMsg = e.getMessage();
}

I'd used smtpClient to replace the JavaMail it really works in UNIX but it will show error : connection reset if you run it in Window environment.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

props.put("mail.smtp.host", host);

with this line you set the SMTP server you will be using. The machine which throws that exception CAN NOT resolve this address. This can be a DNS issue on that machine. Try to ping mail.smtp.host. Then try to telnet at port 25 of that machine.

hope this helps.
 
daniel ong
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the problem is the UNIX operation server we use do not connect to the same exchange server that we use. So i try the new code for the UNIX environment for a testing. But what to say, it works.

So i just ignore the old code for now. But i'll continue on using JavaMail for other application.
 
I am going to test your electrical conductivity with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic