SMTP server setting for Java Mail

D

durnylka

Hi,

I have a little knowledge of java and have no more ideas how to solve
my problem. Can you please have a look at it?

One of my applications is started via Java Web Start on a client PC.
This application has a possibility to send e-mails. Unfortunately
sending e-mails fails with the following log:

[...]
[10/26/06 13:15:01:413 CEST] 25cc04c4 SystemOut O * HOSTNAME =
linux.client.net
[10/26/06 13:15:01:413 CEST] 25cc04c4 SystemOut O * Matching domain
for linux.client.net
[10/26/06 13:15:02:096 CEST] 25cc04c4 SystemOut O DEBUG:
mail.smtp.class property exists and points to
com.sun.mail.smtp.SMTPTransport
[10/26/06 13:15:02:098 CEST] 25cc04c4 SystemOut O DEBUG SMTP:
useEhlo true, useAuth false
[10/26/06 13:15:02:098 CEST] 25cc04c4 SystemOut O
DEBUG: NOCNOKI trying to connect to host "SMTPHOST.network.com", port
25

[10/26/06 13:15:02:098 CEST] 25cc04c4 WebGroup I SRVE0180I:
[ReportBrowser] [/ReportBrowser] [Servlet.LOG]: WARNING:
ReportJob.localExcecute(): Sending mail message failed for report (omc,
1019482) in REPORTER receivers: (e-mail address removed) Reason:
javax.mail.SendFailedException Message: Sending failed;
nested exception is:
javax.mail.MessagingException: Unknown SMTP host:
SMTPHOST.network.com;
nested exception is:
java.net.UnknownHostException: SMTPHOST.network.com

I can't find where SMTPHOST.network.com is set. Is it possible to
change this value? How to do it? I don't have source code of the
application in question but I hope that there is a way to set SMTP
server hostname without modifying the source code.

FYI: I edited the hostnames in the log.

Can you please help me?
 
M

Manish Pandit

Try this:

Properties properties = System.getProperties();
properties.put("mail.smtp.host", "yoursmtpserver");
Session mailSession = Session.getDefaultInstance(properties, null);
Message email = new MimeMessage(mailSession);
email.setFrom(..);
email.setRecipients(..)
email.setSubject(..);
email.setText(..);
Transport.send(email);

Check out javadocs on the above API usage for more information..

-cheers,
Manish
 
D

durnylka

Manish Pandit napisal(a):
Try this:

Properties properties = System.getProperties();
properties.put("mail.smtp.host", "yoursmtpserver");
Session mailSession = Session.getDefaultInstance(properties, null);
Message email = new MimeMessage(mailSession);
email.setFrom(..);
email.setRecipients(..)
email.setSubject(..);
email.setText(..);
Transport.send(email);

Check out javadocs on the above API usage for more information..

-cheers,
Manish

OK, thanks. But how to give properties to the application? Is it
possible to create a config file with the properties and force the
application to read it during the startup? I don't know it...:-/
 
M

Manish Pandit

OK, thanks. But how to give properties to the application? Is it
possible to create a config file with the properties and force the
application to read it during the startup? I don't know it...:-/

Yes, it is possible. Some (easy) ways are :

-By having a properties file on the disk with name=value formatted
properties
-Using -D<name>=<value> option for the jvm when you run your program.

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top