Dear all,

I am about to implement a user feedback page, by using the smtp server of my university.
When I try to send a form, an error message is received as below:
Could not connect to SMTP host: smtp-auth.bris.ac.uk, port: 587
I tested with telnet this smtp address, along with the port number.

telnet smtp-auth.bris.ac.uk 587

This works fine, I can connect to it. Besides, I configured an email client where I set up the right protocol TLS/STARTTLS, and I used my username/password. It is also working fine.
So, the problem might be with my embedded Java code in JSP.

First of all, I tested my web server to send a test email in JSP without SMTP authentication. This works fine.
But, I am not able to find out what is wrong/missing in my code below to send successfully messages with authentication.
Please have a look at it, and any recommendation is welcome!

import="java.util.*;
import="java.io.*;
import="javax.mail.*;
import="javax.event.*;
import="javax.mail.internet.*;
import="java.security.Security.*;
import="javax.activation.*;

	 
  		Properties props = new Properties();
 
		props.put("mail.smtp.host", "smtp-auth.bris.ac.uk");
		props.put("mail.smtp.port","587");
		props.put("mail.debug", "true"); 
		props.put("mail.smtp.debug", "true");
		props.put ("mail.smtp.starttls.enable", "true"); 
		props.put("mail.transport.protocol", "smtp");

		props.put("mail.smtp.socketFactory.port", "587");
		props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");
 
		java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

		Authenticator auth = new javax.mail.Authenticator() {
		protected PasswordAuthentication getPasswordAuthentication(){

		return new PasswordAuthentication("myUsername", "myPassword");
		}
		};

		Session s = Session.getInstance(props,auth);


  		MimeMessage message = new MimeMessage(s);
  		InternetAddress from = new InternetAddress("myFriendAddress");
  		message.setFrom(from);
  
  		InternetAddress to = new InternetAddress("myAddress");
  		message.addRecipient(Message.RecipientType.TO, to);
  		message.setSubject("Test from JavaMail.");
  		message.setText("Hello from JavaMail!");
  		message.saveChanges(); 

			Transport transport = s.getTransport("smtp");
			transport.connect("smtp-auth.bris.ac.uk","myUsername","myPassword");
			transport.sendMessage(message,message.getAllRecipients());
			transport.close();

Thank you very much, in advance.
Norbert

don't use JSP to send email.

Unfortunately, my problem is not solved yet.
So, if you can spot what is missing in my code or why it might not work, your response is more than welcome!

Thanks,
Norbert

what's missing is a good spanking of you for even attempting to do such a thing using JSP.

i need jsp code for sending email and receiving te mail....from my website..pls reply soon

while i am using this code i vl get from address is my address but i never got from address as my friend's email address what i have to do

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.