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.


8 posts

Wannabe Geek


Topic # 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
BDFL - Memuneh
61006 posts

Uber Geek
+1 received by user: 11843

Administrator
Trusted
Geekzone
Lifetime subscriber

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

Does the e-mail client support SSL connections?

Have you contacted the developer for support?





4310 posts

Uber Geek
+1 received by user: 152

Mod Emeritus
Trusted
Lifetime subscriber

  Reply # 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



8 posts

Wannabe Geek


Reply # 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]


BDFL - Memuneh
61006 posts

Uber Geek
+1 received by user: 11843

Administrator
Trusted
Geekzone
Lifetime subscriber

1 post

Wannabe Geek


  Reply # 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.



8 posts

Wannabe Geek


Reply # 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

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Intel introduces new NUC kits and NUC mini PCs
Posted 16-Aug-2018 11:03


The Warehouse leaps into the AI future with Google
Posted 15-Aug-2018 17:56


Targus set sights on enterprise and consumer growth in New Zealand
Posted 13-Aug-2018 13:47


Huawei to distribute nova 3i in New Zealand
Posted 9-Aug-2018 16:23


Home robot Vector to be available in New Zealand stores
Posted 9-Aug-2018 14:47


Panasonic announces new 2018 OLED TV line up
Posted 7-Aug-2018 16:38


Kordia completes first live 4K TV broadcast
Posted 1-Aug-2018 13:00


Schools get safer and smarter internet with Managed Network Upgrade
Posted 30-Jul-2018 20:01


DNC wants a safer .nz in the coming year
Posted 26-Jul-2018 16:08


Auldhouse becomes an AWS Authorised Training Delivery Partner in New Zealand
Posted 26-Jul-2018 15:55


Rakuten Kobo launches Kobo Clara HD entry level reader
Posted 26-Jul-2018 15:44


Kiwi team reaches semi-finals at the Microsoft Imagine Cup
Posted 26-Jul-2018 15:38


KidsCan App to Help Kiwi Children in Need
Posted 26-Jul-2018 15:32


FUJIFILM announces new high-performance lenses
Posted 24-Jul-2018 14:57


New FUJIFILM XF10 introduces square mode for Instagram sharing
Posted 24-Jul-2018 14:44



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.

Alternatively, you can receive a daily email with Geekzone updates.