Hi, This is another way I was trying to send my mail. Maybe you could help me out here. We have an SMTP server(server name and other details are available). I am trying to send my mail via this server (and not gmail this time).
However, the code is compiling fine but gives a runtime error.Please have a look and tell me what is wrong. ------------------------------------------ Code:- --------------------------------------------------------------------------- import javax.mail.*; import javax.mail.internet.*; import javax.mail.Authenticator; import javax.mail.PasswordAuthentication; import java.util.Properties; public class javamailauth { private static final String SMTP_HOST_NAME = "*********.****.**.**"; private static final String SMTP_AUTH_USER = "******"; private static final String SMTP_AUTH_PWD = "*******"; public static void main(String[] args) throws Exception{ new javamailauth().test(); } public void test() throws Exception{ Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.port",80); props.put("mail.smtp.auth", "true"); Authenticator auth = new SMTPAuthenticator(); Session mailSession = Session.getDefaultInstance(props, auth); // uncomment for debugging infos to stdout // mailSession.setDebug(true); Transport transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession); message.setContent("This is a test", "text/plain"); message.setFrom(new InternetAddress("jit...@it.iitb.ac.in")); message.addRecipient(Message.RecipientType.TO,new InternetAddress(" jiteshbdun...@gmail.com")); transport.connect(); transport.sendMessage(message,message.getRecipients( Message.RecipientType.TO)); transport.close(); } private class SMTPAuthenticator extends javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { String username = SMTP_AUTH_USER; String password = SMTP_AUTH_PWD; return new PasswordAuthentication(username, password); } } } --------------------------------------------------------------------------- Error:- --------------------------------------------------------------------------- C:\Program Files\Java\jdk1.5.0_10\bin>java javamailauth Exception in thread "main" javax.mail.MessagingException: Could not connect to S MTP host: smtp-auth.iitb.ac.in, port: 80; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1545) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:45 3) at javax.mail.Service.connect(Service.java:313) at javax.mail.Service.connect(Service.java:172) at javax.mail.Service.connect(Service.java:121) at javamailauth.test(javamailauth.java:38) at javamailauth.main(javamailauth.java:17) Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1511) ... 6 more C:\Program Files\Java\jdk1.5.0_10\bin> ------------------------------------------- Note: For connecting to the internet, we use a UserName and Password . Once this is done, we can go and browse any page, include the mailing websites( our institution mail box too). After this authentication, we goto the institution email website and enter our Email UserName and Password. Am I entering the credentials correctly. My PC's Ip Address has been added to the MTA of the SMTP server. Thus the emails must be relayed properly. Please help. Thanks & Regards, Jitesh Dundas On Fri, Jul 17, 2009 at 11:02 AM, Vasile Braileanu < vasilebraile...@gmail.com> wrote: > Hi, > Did you use a SSL connection on port 465? > > Best regards, > Vasile Braileanu > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---