0

i want to send mail through from my website. i used the below code

String host="smtp.gmail.com", 
		user="username", 
		pass="password";

			//host = smtp_server; //"smtp.gmail.com"; user = jsp_email; //"YourEmailId@gmail.com" // email id to send the emails

			//pass = jsp_email_pw; //Your gmail password

			String SSL_FACTORY ="javax.net.ssl.SSLSocketFactory";

			String to = email;// out going email id

			String from ="emailid"; //Email id of the recipient

			String subject ="Account Information";

			

			String messageText ="hi";

			boolean sessionDebug = true;

			Properties props = System.getProperties();

			props.put("mail.host", host);

			props.put("mail.transport.protocol", "smtp");

			props.put("mail.smtp.auth", "true");
		
			

			props.put("mail.smtp.port", "465");
			props.put("mail.debug", "true");
			props.put("mail.smtp.socketFactory.fallback", "false");

			props.put("mail.smtp.socketFactory.class", SSL_FACTORY);

			Session mailSession = Session.getDefaultInstance(props,null);

			mailSession.setDebug(sessionDebug);

			Message msg =new MimeMessage(mailSession);
			try
			{


			msg.setFrom(new InternetAddress(from));

			InternetAddress[] address = {new InternetAddress(to)};

			msg.setRecipients(Message.RecipientType.TO, address);

			msg.setSubject(subject);

			msg.setContent(messageText,"text/html"); // use setText if you want to send text

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

			transport.connect(host, user, pass);

			
			transport.sendMessage(msg, msg.getAllRecipients());
			/
			//WasEmailSent = true; // assume it was sent
			transport.close();
			}

			catch
			(Exception err) {

			//WasEmailSent = false; // assume it's a fail

			out.println("Error"+err.getMessage());

			}

it worked fine with my friends system. but i get the below error


Loading javamail.default.providers from jar:file:/H:/dinesh/wasce with java1.5/wasce with java1.5/repository/default/darkhorse/1.0/darkhorse-1.0.car/WEB-INF/lib/mail.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@25a225a2; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
DEBUG SMTP: useEhlo true, useAuth true

DEBUG: SMTPTransport trying to connect to host "smtp.gmail.com", port 465

DEBUG SMTP RCVD:
DEBUG: SMTPTransport could not connect to host "smtp.gmail.com", port: 465

we both use the same providers...
i have turned of the firewall and even uninstalled the anti virus....
i have got struck in this for one week
plz help me out from this....

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jwenting
0

i did java mail before after tons of research, you have to know yr internet provider host(SMTP) example, singtel (singapore) one is "mail.singnet.com.sg". And there is no such thing as free SMTP. its either unstable, unworkable or just a scam. if you are publishing this website, just check whats the provider host(SMTP) for your wehosting company.

0

anyone opening up their smtp server for the world is just creating an open spam relay and soon finds their server blacklisted by the entire planet.

So even if doing javamail inside a jsp were smart (it isn't) trying to use a public mail server you don't have explicit credentials to use is idiotic.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.