Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


saguna

8 posts

Wannabe Geek


#9052 15-Aug-2006 19:21
Send private message

Hi,

Could you tell me why I am unable to send mail from my javamail client for gmail and yahoo. I am getting the error:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.SocketException: Connectiopn timedout...

I am able to connect to the mail server for my university and can send messages. But I cannot understand as to what the problem is with gmail and yahoo. I have tried using port 465 for gmail and 587 for yahoo. Also I am using authentication. Is it because the smtp server is not present at the links smtp.gmail.com and smtp.mail.yahoo.com or is it because they can only be accessed using a browser. I am really confused. Your help will be really appreciated!

Regards
Saguna

Create new topic
freitasm
BDFL - Memuneh
80652 posts

Uber Geek
+1 received by user: 41038

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

#44038 15-Aug-2006 19:37
Send private message

Does the e-mail client support SSL connections?

Have you contacted the developer for support?





Referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies 

 

Support Geekzone by subscribing (browse ads-free), or making a one-off or recurring donation through PressPatron.

 




bradstewart
4338 posts

Uber Geek
+1 received by user: 166

Retired Mod
Trusted
Lifetime subscriber

  #44042 15-Aug-2006 19:58
Send private message

Incoming Mail (POP3) Server - requires SSL:pop.gmail.com
Use SSL: Yes
Port: 995
Outgoing Mail (SMTP) Server - requires TLS:smtp.gmail.com (use authentication)
Use Authentication: Yes
Use STARTTLS: Yes (some clients call this SSL)
Port: 465 or 587
Account Name: your Gmail username (including '@gmail.com')
Email Address: your full Gmail email address (username@gmail.com)
Password: your Gmail password

saguna

8 posts

Wannabe Geek


#44048 15-Aug-2006 20:53
Send private message

Thanks guys!! this was really prompt! but i have already tried doing this. This is what the javamail client looks like:


import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;

public class MailClient extends Frame {
   
 
 String mailHost = "smtp.monash.edu.au";
 Label toLabel = new Label("To:");
 Label fromLabel = new Label("From:");
 Label subjectLabel = new Label("Subject:");
 Label contentLabel = new Label("Content:");
 Label statusLabel = new Label("Status:");
 TextField destination = new TextField();
 TextField source = new TextField();
 TextField subject = new TextField();
 TextArea content = new TextArea(); 
 Button send = new Button("Send Message");
 TextArea status = new TextArea();
 
 public static void main(String args[]){
  MailClient app = new MailClient();
 }
 
 public MailClient() {
  super("MailClient");
  setup();
  addWindowListener(new WindowEventHandler());
  setSize(550,450);
  show();
 }
 
 void setup() {
  setupMenuBar();
  layoutComponents();
  send.addActionListener(new ButtonHandler());
 }
 
 void setupMenuBar() {
  MenuBar menuBar = new MenuBar();
  Menu fileMenu = new Menu("File");
  MenuItem fileExit = new MenuItem("Exit");
  fileExit.addActionListener(new MenuItemHandler());
  fileMenu.add(fileExit);
  menuBar.add(fileMenu);
  setMenuBar(menuBar);
 }
 
 void layoutComponents() {
  int x = 10;
  int y = 50;
  // Set bounds
  toLabel.setBounds(x,y,50,25);
  destination.setBounds(x+70,y,300,25);
  fromLabel.setBounds(x,y+40,50,25);
  source.setBounds(x+70,y+40,300,25);
  subjectLabel.setBounds(x,y+80,50,25);
  subject.setBounds(x+70,y+80,300,25);
  contentLabel.setBounds(x,y+120,50,25);
  content.setBounds(x+70,y+120,300,100);
  statusLabel.setBounds(x,y+240,50,25);
  status.setBounds(x+70,y+240,300,100);
  send.setBounds(400,y,100,30);
  // Add components
  add(toLabel);
  add(destination);
  add(send);
  add(fromLabel);
  add(source);
  add(subjectLabel);
  add(subject);
  add(contentLabel);
  add(content);
  add(statusLabel);
  add(status);
  add(new Label(""));
 }
 
 void sendMessage() {
  Properties properties = new Properties();
 
  properties.put("mail.smtp.user", "***@infotech.monash.edu.au");
  properties.put("mail.smtp.password", "*******");
  properties.put("mail.smtp.host",mailHost);
  properties.put("mail.smtp.port", "465");
  properties.put("mail.smtp.startssl.enable","true");
  properties.put("mail.smtp.starttls.enable","true");
  properties.put( "mail.smtp.auth", "true");
  properties.put("mail.smtp.debug", "true");
  properties.put("mail.from",source.getText());
 

  try {
     
   Authenticator auth = new SMTPAuthenticator(); 
   Session session = Session.getInstance(properties, auth);
   session.setDebug(true);
   Message message = new MimeMessage(session);
   InternetAddress[] address =
    {new InternetAddress(destination.getText())};
   message.setRecipients(Message.RecipientType.TO, address);
   message.setFrom(new InternetAddress(source.getText()));
   message.setSubject(subject.getText());
   message.setContent(content.getText(),"text/plain");
   Transport transport = session.getTransport(address[0]);
   transport.addConnectionListener(new ConnectionHandler());
   transport.addTransportListener(new TransportHandler());
   transport.connect();
   message.saveChanges();
   transport.sendMessage(message,address);
  }catch(Exception e){
   status.setText(e.toString());
  }
 }

 private class SMTPAuthenticator extends javax.mail.Authenticator {

public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("***@infotech.monash.edu.au", "*******");
}
}
 
 class ConnectionHandler extends ConnectionAdapter {
  public void opened(ConnectionEvent e) {
   status.setText("Connection opened.");
  }
  public void disconnected(ConnectionEvent e) {
   status.setText("Connection disconnected."); 
  }
  public void closed(ConnectionEvent e) {
   status.setText("Connection closed."); 
  }
 }
 
 class TransportHandler extends TransportAdapter {
  public void messageDelivered(TransportEvent e) {
   status.setText("Message delivered."); 
  }
  public void messageNotDelivered(TransportEvent e) {
   status.setText("Message NOT delivered."); 
  }
  public void messagePartiallyDelivered(TransportEvent e) {
   status.setText("Message partially delivered."); 
  }
 }

 class ButtonHandler implements ActionListener {
  public void actionPerformed(ActionEvent ev){
   String s=ev.getActionCommand();
   if(s.equals("Send Message")) sendMessage();
  }
 }

 class MenuItemHandler implements ActionListener {
  public void actionPerformed(ActionEvent ev){
   String s=ev.getActionCommand();
   if(s=="Exit"){
    System.exit(0);
   }
  }
 }

 class WindowEventHandler extends WindowAdapter {
  public void windowClosing(WindowEvent e){
   System.exit(0);
  }
 }
 
}


This code works fine with my monash smtp mail server but with gmail and yahoo it gives a timeout error or sometimes a network unreachable error!! The mail client is part of the application I am tryin to develop. I am also now realizing that is this because I am using a VPN connection for Internet and the proxy is not allowing me to connect to the server?? If so how do I go around this problem?


[Moderator edit (MF): removed email address]




freitasm
BDFL - Memuneh
80652 posts

Uber Geek
+1 received by user: 41038

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

#44052 15-Aug-2006 21:11
Send private message

No way around it really...





Referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies 

 

Support Geekzone by subscribing (browse ads-free), or making a one-off or recurring donation through PressPatron.

 


xand
1 post

Wannabe Geek
Inactive user


  #44668 25-Aug-2006 02:28
Send private message

Hi,

I used approach provided here: http://blog.xand.es/blog.php/javamail-gmail/post.htm#comments

It worked for me, the only think you should do is configure right your javax.mail.Session.

saguna

8 posts

Wannabe Geek


#44669 25-Aug-2006 02:39
Send private message

Hey thx! the code had worked long back, im sorry i didnt update it here! the only problem was i was behind a proxy!
and also it worked with port 587. So, I used a direct internet connection and there was no problem!! thx neways.

Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.