Sign in to follow this  
Tree Penguin

[web] JSP: sending e-mails

Recommended Posts

Hi, i am having problems sending emails with my current ISP from a JSP page or Java. When i run a mail server at localhost i have no problem connecting to it, but when i try to connect to my ISP's server i get a javax.mail.AuthenticationFailedException. It works fine in Outlook (without encryption), with the same host, port, username and password i used here. So i guess it's just some variable i need to set or something. At the moment i am using this code:
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.host.nl");
props.put("mail.smtp.protocol", "smtp");
props.put("mail.smtp.user","username");		// Tried username@host.nl
props.put("mail.smtp.password","password");	// Works in Outlook
props.put("mail.smtp.auth","true");		// false gives connection refused

props.put("mail.smtp.port", "25");
props.put("mail.smtp.starttls.enable","true");	// Tried false, same problem

Session session2 = Session.getInstance(props, null);

Message msg = new MimeMessage(session2);
if (from != null)
	msg.setFrom(new InternetAddress(from));
else
	msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
	InternetAddress.parse(to));
msg.setSubject(subject);
msg.setContent(text,"text/plain");
msg.setSentDate(new Date());
msg.saveChanges();

Transport.send(msg);

I tried smtps but still the same problem, and i tried every combination for these values i could think of and i always get the authentication exception (or could not connect). Also i tried: Transport transport=session2.getTransport("smtp"); ... Transport.send(msg); Instead of Transport.send(msg) but it gave me the same problems. Did i miss anything?

Share this post


Link to post
Share on other sites
Have you tried:

1. Using a network analyser to see what errors the server sends back?
2. Connecting manually using (e.g.) Telnet to see what happens then?

Normally for a web application to send mail I'd suggest that running a local MTA is essential, to queue messages for the smart host - otherwise, in the event of your smart host being down, mail will get lost.

Mark

Share this post


Link to post
Share on other sites
Have you contacted your network administrator about the correct SMTP smart host to use?

I still think that running a local MTA is the right way to go about this.

Mark

Share this post


Link to post
Share on other sites
As i said Outlook works fine, but telnet and java mail don't. And i don't really feel like being put on hold for 2 hours to ask a question they probably won't answer anyway.

Do you recommend a specific MTA?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this