Question: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1

Ads

 
 
 

Share on Google+Share on Google+

ritu
Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
1 Answer(s)      7 years ago
Posted in : JavaMail
package beans;
import java.io.*;
import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.search.FlagTerm;

public class ReplyMail {
static String host = "imap.gmail.com";
static String user = "riteshdiwakar87";
static String password = "xyz";
static String to="[email protected]";

public static void main(String args[]) throws MessagingException{
try{
Properties props=new Properties();
Session session=Session.getDefaultInstance(props,null);
Store store=session.getStore("imaps");
store.connect(host, user, password);

System.out.print(store.isConnected());
//=====================================================================================================================
Folder fldr=store.getFolder("inbox");
fldr.open(Folder.READ_ONLY);
Message[] msg=fldr.getMessages();
MimeMessage msgs=null;
String sender;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<msg.length;i++){
System.out.println("subject====="+msg[i].getSubject());
System.out.print("Do you want to reply [y/n] : ");
String ans = reader.readLine();
if(ans.equals("y")||ans.equals("Y")){
msgs=(MimeMessage)msg[i].reply(true);
System.out.println("msg subject="+msgs.getSubject().toString());
sender=msg[i].getAllRecipients()[0].toString();
System.out.println("msg sender=:"+sender);
msgs.setSender(new InternetAddress(sender));
System.out.println(msgs.getSender());
String content="<html><head></head><body>kjdfgkdfgkdgkdjgkjdfng"+msg[i].getContent()+"</body></html>";
msgs.setContent(content,"text/html");
System.out.println("content "+msgs.getContent());
msgs.addRecipient(Message.RecipientType.TO, new InternetAddress(sender));
break;

}
if(ans.equals("n")||ans.equals("N")){
continue;
}
}
store.close();
Properties prps=System.getProperties();
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
prps.put("mail.smtp.socketFactory.port", "465");
prps.put("mail.smtp.socketFactory.class",SSL_FACTORY);
prps.put("mail.smtp.socketFactory.fallback", "false");
prps.setProperty("mail.transport.protocol", "smtp");
prps.setProperty("mail.smtp.host", "smtp.gmail.com");
//prps.put("mail.smtp.auth", "true");
//prps.put("mail.smtp.port", "465");
//prps.put("mail.debug", "true");
session = Session.getInstance(prps,new javax.mail.Authenticator() {
String pass="xyz";
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("riteshdiwakar87",pass);
}
});

session.setDebug(true);
System.out.println("ritu");

Transport transport = session.getTransport();
System.out.println("ritu");
transport.connect();
System.out.println(transport.isConnected());
System.out.println(msgs.getContentType());
System.out.println(msgs.getSentDate());
//Transport.send(msgs);
transport.send(msgs);
System.out.println("ritu");

//transport.close();
//=================================================================================================================================

}
catch(Exception ee){
System.out.println("exception "+ee);
}


}

}

this is my application .
i am facing an exception which is
"javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1".....
send me solution of this .
ritesh
thank you

Ads
View Answers

May 13, 2010 at 11:06 AM


Hi Friend,

Please visit the following link:

http://www.roseindia.net/javamail/

Hope that it will be helpful for you.
Thanks

Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training program paradigams program paradigams program paradigams automatically resend when connection lost in sending email automatically resend when connection lost in sending email automatically resend when connection lost in sending email java mail send using setText() how to send message java code to send email using gmail smtp server Sending email with read and delivery requests values of the "from address & to addresses" while sending a mail to localhost using javamail projects Autodownload email attachments Reading the body of mail excluding the signature how to send contact detail in email problem in viewing the mail's content using javamail how to send mail with multiple attachments in jsp Core java Exception in thread java mail java mail API sending mail using jsp attendance management system source code Multiplication table code for sending email using j2me audio video conferencing Java Email automate mails in lotus notes java mail sending with images Code for opening a new mail from the default mail box and copy the database contents Sending Emails In Java Sending Emails In Java Sending Emails In Java sending email using smtp in java java mail programs How to send sms alerts to mobile using java? get from address using javamail api? mail java How can java programs execute automatically when it connects to network I want complete tutorial on advanced java email java result after compilation TEST JAMES MAIL SERVER i need a help in this please javamail help in java help in java Request URl using Retrive data from dtabase

Ads

 
Advertisement null

Ads