User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 427,225 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,233 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1833 | Replies: 4
Reply
Join Date: Jun 2008
Posts: 2
Reputation: webmania_bt is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
webmania_bt webmania_bt is offline Offline
Newbie Poster

Sending email in JSP with SMTP authentication

  #1  
Jun 27th, 2008
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
Last edited by webmania_bt : Jun 27th, 2008 at 8:43 am. Reason: mispelling
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Sending email in JSP with SMTP authentication

  #2  
Jun 28th, 2008
don't use JSP to send email.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Jun 2008
Posts: 2
Reputation: webmania_bt is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
webmania_bt webmania_bt is offline Offline
Newbie Poster

Re: Sending email in JSP with SMTP authentication

  #3  
Jul 9th, 2008
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
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Sending email in JSP with SMTP authentication

  #4  
Jul 9th, 2008
what's missing is a good spanking of you for even attempting to do such a thing using JSP.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Jan 2008
Posts: 12
Reputation: senthil_sivanat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
senthil_sivanat senthil_sivanat is offline Offline
Newbie Poster

Re: Sending email in JSP with SMTP authentication

  #5  
Jul 23rd, 2008
This page has code to send mail from GMail SMTP. Copy the code and run it.

If necessary add some concatenation operator.

http://jspcodes.elementfx.com/codesn...d=7&category=1
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 11:34 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC