Results 1 to 6 of 6
Thread: java Mail Problem Please Help
- 05-30-2011, 12:06 AM #1
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
java Mail Problem Please Help
this is my Code:
Java Code:import java.util.Properties; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage.RecipientType; public class SendMail { private static String HOST = "smtp.gmail.com"; private static String USER = "java.web.programming";//"yourmail.com"; private static String PASSWORD = "javaprogramming"; private static String PORT = "587"; private static String FROM = "mail.com"; private static String TO; private static String STARTTLS = "true"; private static String AUTH = "true"; private static String DEBUG = "true"; private static String SOCKET_FACTORY = "javax.net.ssl.SSLSocketFactory"; private static String SUBJECT = "Testing JavaMail API"; private static String TEXT = "This is a test message from my java application. Just ignore it"; public synchronized void send(String to) { TO = to; //Use Properties object to set environment properties Properties props = new Properties(); props.put("mail.smtp.host", HOST); props.put("mail.smtp.port", PORT); props.put("mail.smtp.user", USER); props.put("mail.smtp.auth", AUTH); props.put("mail.smtp.starttls.enable", STARTTLS); props.put("mail.smtp.debug", DEBUG); props.put("mail.smtp.socketFactory.port", PORT); props.put("mail.smtp.socketFactory.class", SOCKET_FACTORY); props.put("mail.smtp.socketFactory.fallback", "false"); try { //Obtain the default mail session Session session = Session.getDefaultInstance(props, null); session.setDebug(true); //Construct the mail message MimeMessage message = new MimeMessage(session); message.setText(TEXT); message.setSubject(SUBJECT); message.setFrom(new InternetAddress(FROM)); message.addRecipient(RecipientType.TO, new InternetAddress(TO)); message.saveChanges(); //Use Transport to deliver the message Transport transport = session.getTransport("smtp"); transport.connect(HOST, USER, PASSWORD); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } catch (Exception e){ e.printStackTrace(); } } public static void main(String[] args){ (new SendMail()).send("litvak.marina@gmail.com"); } }
and this is the problem:
Java Code:DEBUG: setDebug: JavaMail version 1.4.3 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525) at javax.mail.Service.connect(Service.java:291) at javax.mail.Service.connect(Service.java:172) at SendMail.send(SendMail.java:59) at SendMail.main(SendMail.java:73) Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(Unknown Source) at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(Unknown Source) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:201) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672) ... 5 more
i have tried the two ports 465 and 587 both the same eror's what could be the problem?Last edited by Fubarable; 05-30-2011 at 12:55 AM. Reason: code tags added
-
- 05-30-2011, 01:03 AM #3
Why do you think the server is listening on that port? And that it is willing to connect with your code?Could not connect to SMTP host: smtp.gmail.com, port: 587;
- 05-30-2011, 01:09 AM #4
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
because it's the gmail confrmation for the host and the port.
this code is working fine in my friend laptop but in a diffrent nwetwork i dont know why.
maybe there is somthing that i need to install?
and by the way i dont have any firewall.
- 05-30-2011, 02:01 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
- 05-30-2011, 10:20 AM #6
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Problem while sending a java mail
By dushyant1244 in forum Advanced JavaReplies: 15Last Post: 03-15-2013, 10:37 PM -
Java Mail Api Problem
By ravjot28 in forum NetworkingReplies: 3Last Post: 06-21-2010, 05:19 PM -
Java Mail Multipart Problem
By lowell108 in forum Advanced JavaReplies: 0Last Post: 01-04-2010, 02:36 PM -
problem with sending mail usin javaX.mail api
By sandeepsai39 in forum New To JavaReplies: 4Last Post: 11-25-2009, 05:37 AM -
Problem in sending mail from java
By npoorni in forum Advanced JavaReplies: 1Last Post: 06-30-2009, 04:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks