Results 1 to 6 of 6
- 02-23-2011, 12:52 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
JAVA MAIL Connection Time Out ...
Hey, im not really new to java, but i never worked with this library before, and after i try different ways, i always get connection timed out ...
Can you see anything missing from my code?
Every time that i try to send an email i get connection time out ... Can someone find whats missing in this code?Java Code:import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Sendfile { public static void main(String[] args) { Properties props = new Properties(); /** Parâmetros de conexão com servidor Hotmail */ props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "587"); props.put("mail.smtp.socketFactory.fallback", "false"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "587"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("yourmail", "password"); } }); /** Ativa Debug para sessão */ session.setDebug(true); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("frommail")); //Remetente message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("tomail")); //Destinatário(s) message.setSubject("Enviando email com JavaMail");//Assunto message.setText("Enviei este email utilizando JavaMail com minha conta Hotmail!"); /**Método para enviar a mensagem criada*/ Transport.send(message); System.out.println("Feito!!!"); } catch (MessagingException e) { throw new RuntimeException(e); } } }
thanks ...Last edited by cyberaa; 02-23-2011 at 12:59 AM.
- 02-23-2011, 05:52 AM #2
You should also use the SSLSocketFactory settings or it may give a "Must issue a STARTTLS command first" error.
If you are getting connection time out, try out for other port. May be use 465 instead of 587.
Hope that helps,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 02-23-2011, 12:12 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Hey,
i added the SSLFACTORYSocket and tried both ports and now it works
Thanks alot :P
- 02-23-2011, 12:19 PM #4
You are welcome... :D
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 07-11-2011, 10:04 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 0
Please reply as i did not understand ...
Could you please tell me little elaborative that how you have added the new socket and fix this issue?
- 07-13-2011, 11:00 AM #6
Member
- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
How to Expire the sending link to a mail after particular period of time
By Kadiyala in forum New To JavaReplies: 0Last Post: 02-05-2011, 06:36 AM -
Facing problem in making connection to mail server
By Basit56 in forum New To JavaReplies: 2Last Post: 01-22-2010, 06:27 PM -
Attachments were missing when mail was sent through java mail API
By Malathi in forum Web FrameworksReplies: 2Last Post: 06-04-2009, 01:42 PM -
Javax.mail.MethodNotSupported Exception in java mail api
By namarc in forum Advanced JavaReplies: 2Last Post: 05-05-2008, 06:01 AM -
Calculating the DB connection time
By Java Tip in forum Java TipReplies: 0Last Post: 01-20-2008, 08:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks