Hi, Many thanks for your reply(Also for the usage of your code on my other email id:-jiteshbdun...@gmail.com <id%3a-jiteshbdun...@gmail.com> :) ).
I implemented the code that you told me to add: Code is as follows:- ------------------------------------------ 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.starttls.enable","true"); props.put("mail.smtp.socketFactory.port", 465); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); //props.put("mail.smtp.port",25); 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 that I get is :- --------------------------------------- C:\Program Files\Java\jdk1.5.0_10\bin>java javamailauth DEBUG: setDebug: JavaMail version 1.4.2 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s mtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp-auth.iitb.ac.in", port 25, isSSL fal se Exception in thread "main" javax.mail.MessagingException: Could not connect to S MTP host: smtp-auth.iitb.ac.in, port: 25; 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:44) 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 com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java :549) at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketI mpl.java:141) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:201) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1511) ... 6 more C:\Program Files\Java\jdk1.5.0_10\bin> ---------------------------------------- Is this some kind of authentication problem? The code is compiling fine but it gives the above runtime error. Thanks & Regards, Jitesh Dundas On Tue, Jul 21, 2009 at 7:11 PM, pacior <gpaty...@gmail.com> wrote: > > What You need is to write code responsible for using ssl withjavamail > api: > For instance, for gmail, ssl port is 465: > > props.put("mail.smtp.starttls.enable","true"); > props.put("mail.smtp.auth", "true"); > //props.put("mail.smtp.debug", "true"); > props.put("mail.smtp.socketFactory.port", 465); > props.put("mail.smtp.socketFactory.class", > "javax.net.ssl.SSLSocketFactory"); > props.put("mail.smtp.socketFactory.fallback", "false"); > > Grzegorz Patynek > > On 21 Lip, 16:20, jitesh dundas <jbdun...@gmail.com> wrote: > > Hi Frends, > > > > I changed the port to 25 as this is the one used for sending emails. Now > I > > am getting this error:- > > > > C:\Program Files\Java\jdk1.5.0_10\bin>java Mailer > > There was an error in sending the mail. Please check the username, > password > > and > > the mail-server information provided > > javax.mail.SendFailedException: Invalid Addresses; > > nested exception is: > > com.sun.mail.smtp.SMTPAddressFailedException: 554 < > > jit...@it.iitb.ac.in> > > : Relay access denied > > ; > > nested exception is: > > com.sun.mail.smtp.SMTPAddressFailedException: 554 < > > jbdun...@gmail.com>: > > Relay access denied > > > > at > com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1446) > > at > > com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:736) > > at javax.mail.Transport.send0(Transport.java:191) > > at javax.mail.Transport.send(Transport.java:120) > > at Mailer.postMail(Mailer.java:82) > > at Mailer.main(Mailer.java:30) > > Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 < > > jit...@it.iitb.ac. > > in>: Relay access denied > > ; > > nested exception is: > > com.sun.mail.smtp.SMTPAddressFailedException: 554 < > > jbdun...@gmail.com>: > > Relay access denied > > > > at > com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1344) > > ... 5 more > > Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 < > > jbdun...@gmail.com > > > > >: Relay access denied > > > > ... 6 more > > > > C:\Program Files\Java\jdk1.5.0_10\bin> > > > > Please help.. > > Thanks & Regards, > > Jitesh Dundas > > > > On Tue, Jul 21, 2009 at 3:54 PM, jitesh dundas <jbdun...@gmail.com> > wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---