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:, port: 587
I tested with telnet this smtp address, along with the port number.

telnet 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!


  		Properties props = new Properties();
		props.put("", "");
		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", "");
		props.put("mail.smtp.socketFactory.fallback", "false");;

		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");
  		InternetAddress to = new InternetAddress("myAddress");
  		message.addRecipient(Message.RecipientType.TO, to);
  		message.setSubject("Test from JavaMail.");
  		message.setText("Hello from JavaMail!");

			Transport transport = s.getTransport("smtp");

Thank you very much, in advance.

Recommended Answers

don't use JSP to send email.

Jump to Post

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

Jump to Post

All 6 Replies

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!


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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.