# [web] JSP: sending e-mails

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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.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)
else
msg.setFrom();
msg.setRecipients(Message.RecipientType.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 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 on other sites
Ok, telnet does work, but not from the pc that's connected to the ISP's network. It doesn't make any sense. I'll try a network analyzer.

Mark

##### 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 on other sites

This topic is 4092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.