Javax.mail.MessagingException: Could not connect to SMTP host:

here is a part of my code
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Mail {
/** Creates a new instance of PostMail */
public Mail() {
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp."_____".com");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
Here is the exception i rec'vd
javax.mail.MessagingException: Could not connect to SMTP host: smtp.google.com, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at Mail.postMail(Mail.java:45)
at ArchMain.<init>(ArchMain.java:30)
at ArchMain$6.run(ArchMain.java:360)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.net.ConnectException: Connection refused: 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:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 17 more

package MailDao;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import java.text.*;
import java.text.DateFormat.* ;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.activation.*;
import javax.mail.search.*;
import java.util.Vector.*;
import java.sql.*;
public class SendMail {
String SMTP_HOST_NAME = "smtp.techpepstechnology.com";//smtp.genuinepagesonline.com"; //techpepstechnology.com";
String SMTP_AUTH_USER = "[email protected]"; //[email protected]"; //techpeps";
String SMTP_AUTH_PWD = "demo"; //techpeps2007";
public void postMail( String recipients[ ], String subject,
String message , String from,String msgType) throws MessagingException {
boolean debug = false;
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
// create a message
MimeMessage msg = new MimeMessage(session);
// MimeMessage mimemessage = new MimeMessage(simplemailuser.getSession());
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
if(msgType.equalsIgnoreCase("")) {
//mimemessage.setText(s4);
msg.setContent(message, "text/plain");
else {
MimeBodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText(message);
MimeBodyPart fileBodyPart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(msgType);
fileBodyPart.setDataHandler(new DataHandler(fds));
fileBodyPart.setFileName(fds.getName());
//step:5 create the multipart/container to hold the part
Multipart container = new MimeMultipart();
container.addBodyPart(textBodyPart);
container.addBodyPart(fileBodyPart);
//step:6 add the multipart to the actual message
msg.setContent(container);
try{
Transport transport=session.getTransport("smtp");
transport.connect();
transport.send(msg);
transport.close();
}catch(Exception e) {
e.printStackTrace();
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);
public static void main(String arg[]) {
SendMail sm = new SendMail();
String[] s ={"[email protected]"};
try{
sm.postMail(s,"hello","This is testing of mail","[email protected]","");
catch(Exception e)
e.printStackTrace();
//sm.sendMsg("demo", "demo");
System.out.println("Mail Sent");
i also got the follwing error this code work fine in jcreator but i used this in netbeans it throws a exception
plz.....help
javax.mail.MessagingException: Could not connect to SMTP host: smtp.techpepstechnology.com, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:867)
Mail Sent
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:156)
at javax.mail.Service.connect(Service.java:256)
at javax.mail.Service.connect(Service.java:135)
at javax.mail.Service.connect(Service.java:87)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:93)
at MailDao.SendMail.postMail(SendMail.java:86)
at MailDao.SendMail.main(SendMail.java:110)

Similar Messages

  • JavaMail MessagingException: could not connect to SMTP

    Hello, I am getting this exception when i run my program.
    Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: mail.smart.com.ph, port: 25, response: -1
         at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1379)
         at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
         at javax.mail.Service.connect(Service.java:310)
         at javax.mail.Service.connect(Service.java:169)
         at javax.mail.Service.connect(Service.java:118)
         at javax.mail.Transport.send0(Transport.java:188)
         at javax.mail.Transport.send(Transport.java:118)
         at sendEmail.postMail(sendEmail.java:136)
         at sendEmail.main(sendEmail.java:99)
    I dont know what response: -1 means. Does anyone know what this means? Thanks in advance. By the way, is port 25 the default port that all SMTps listen to?

    Additional info, I've tried another SMTP and port, but I think the program just hangs.
    The SMTP that I'm using is from my Outlook.. From the Mail Setup > Microsoft Exchange Server. And I got the port by running the command prompt > netstat.

  • When will come this error Could not connect to SMTP host: son1175, port: 25

    Hi all
    we configure SMTP server on Linux ES,my java application run on same server
    from my application trying to send a mail i got this error
    [0] EmailConnection.getConnection: Attempting connection...
    DEBUG: setDebug: JavaMail version 1.3.1
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
    DEBUG SMTP: useEhlo true, useAuth false
    DEBUG SMTP: trying to connect to host "son1175", port 25
    [0] EmailConnection.getConnection: Cannot connect to server with configuration
    smtp://padmanab:*@son1175/. Port = 25. Security: none.
    Properties: {mail.port=25, mail.smtp.timeout=30000, mail.smtp.connectiontimeout=30000}
    Could not connect to SMTP host: son1175, port: 25;
    nested exception is:
    java.net.ConnectException: Connection refused
    2005-03-30 10:03:03,751 INFO [plt.userManagement] [PoolThread-9] "Password Reset" email could not be sent to vallish at the email address, "[email protected]".
    but mail server is configured currectly
    please tell cause of this error out java application or my SMTP server
    regards
    satya

    Could not connect to SMTP host: son1175, port: 25;
    nested exception is:
    java.net.ConnectException: Connection refusedYou didn't notice that this question is asked every day here?
    Your computer can't connect to a computer named "son1175", or if it can then that computer isn't running a server listening at port 25. Talk to your network people if your computer name is the right one and ask them why not. It is nothing to do with programming.

  • HT1277 can receive bat can't send yahoo mail massage could not connect to smtp what to do?

    can receive but can't send yahoo mail,coffline) what to do?
    please help,
    thanks
    Roee

    See OS X Mail: Troubleshooting sending and receiving email messages for details. on troubleshooting mail.
    Your SMTP server settings are incorrect.  Mail has two connections, a receive path from your mail server to your mail client, and a send path from your mail client to the mail server.  The send path uses SMTP to communicate with the server.
    Apple Mail.app has separate settings for the receive and send paths; each has its own server, username, password, port and SSL settings.  Your send path settings are likely incorrect. 
    To determine the proper settings, check with Yahoo for the SMTP server settings for your account (usually a web search, but I don't know the details of how Yahoo sets up their accounts by default nor whether that varies by account), and verify that your settings match — the send-path settings are available via the accounts settings; Mail > Preferences > Accounts > select the account > Account Information > and switch the Select SMTP Server setting to Edit SMTP Server List... > select your Yahoo SMTP server, and set the account details per Yahoo requirements.

  • Javamail could not connect to SMTP Server

    Hi, I was bored and decided to create a small email application.
    I tryed to connect to my ISP's SMTP Server but I get the following MessagingException
    I don't know but I think my problem lies within my Authenticator class.
    Please tell me if I am correct and how I would fix it.
    create email -      true
    send   email -      false
    javax.mail.MessagingException: Could not connect to SMTP host: smtp.telkomsa.net, port: 25, response: -1
            at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1379)
            at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
            at javax.mail.Service.connect(Service.java:288)
            at javax.mail.Service.connect(Service.java:169)
            at javax.mail.Service.connect(Service.java:118)
            at javax.mail.Transport.send0(Transport.java:188)
            at javax.mail.Transport.send(Transport.java:118)
            at EMAIL.Email.send(Email.java:101)
            at ENTRY.Start.main(Start.java:15)here is part of my code:
        public boolean createEmail(){
            try{
                props.setProperty( "mail.smtp.host", AddressBook.getHost() );
                session = Session.getDefaultInstance( props,(Authenticator)new MyAuthenticator());
                message = new MimeMessage( session );
                message.setText( text );
                message.setSubject( subject );
                if( AddressBook.containsEntry( from ) ){
                    message.setFrom( new InternetAddress( AddressBook.getAddress( from ) ) );
                } else {
                    if( AddressBook.isValidEmailAddress( from ) ){
                        message.setFrom( new InternetAddress( from ) );
                    } else {
                        throw new Exception( "\"From\" address not valid" );
                for( String recipient : to ){
                    message.addRecipient( Message.RecipientType.TO, new InternetAddress( recipient ) );
                for( String recipient : cc ){
                    message.addRecipient( Message.RecipientType.CC, new InternetAddress( recipient ) );
                for( String recipient : bcc ){
                    message.addRecipient( Message.RecipientType.BCC, new InternetAddress( recipient ) );
                return true;
            }catch( Exception ex ){
                ex.printStackTrace();
                return false;
            return true;
        public boolean send(){
            try{
                Transport.send( message );
                return true;
            }catch( Exception e ){
                e.printStackTrace();
                return false;
        }Authenticator class
    import javax.mail.Authenticator;
    public class MyAuthenticator extends Authenticator{
        @Override
        protected PasswordAuthentication getPasswordAuthentication(){
            return new PasswordAuthentication( "[email protected]", "xxxxxxxx" );
    }

    I have muiltiple for gmail, telkom (My ISP) and work.
    When I try it through gmail it worx but my ISP's smtp host still bounces the message:
    Email recieved from [email protected]
    [email protected] to me
    show details 10:31 PM (10 minutes ago) Reply
    Hi. This is the qmail-send program at telkomsa.net.
    I'm afraid I wasn't able to deliver your message to the following addresses.
    This is a permanent error; I've given up. Sorry it didn't work out.
    Your message was bounced by our server.
           If you have any other queries please contact our support:
    TelkomInternet Support Desk Number: 10215
    TelkomInternet Support Desk Mail: [email protected]
    <[email protected]>:
    Warning: undefined mail delivery mode: normal (ignored).
    The users mailfolder is over the allowed quota (size). (#5.2.2)
    --- Below this line is a copy of the message.
    Return-Path: <[email protected]>
    Received: (qmail 18884 invoked from network); 23 Nov 2008 20:31:06 -0000
    Received: from unknown (HELO ironport1.telkomsa.net) ([xxx.xx.xxx.xxx])
             (envelope-sender <[email protected]>)
             by O (qmail-ldap-1.03) with SMTP
             for <[email protected]>; 23 Nov 2008 20:31:06 -0000
    X-IronPort-Anti-Spam-Filtered: true
    X-IronPort-Anti-Spam-Result: ArwAANpLKUlIDszicWdsb2JhbACSSlQ+AQwKCQkPBa47gQKJfAEDAQOCeQ
    Received: from qb-out-0506.google.com ([72.14.204.226])
    by ironport1.telkomsa.net with ESMTP; 23 Nov 2008 22:31:01 +0200
    Received: by qb-out-0506.google.com with SMTP id f29so1924750qba.33
           for <[email protected]>; Sun, 23 Nov 2008 12:30:59 -0800 (PST)
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
           d=gmail.com; s=gamma;
           h=domainkey-signature:received:received:cc:message-id:subject
            :mime-version:content-type:content-transfer-encoding:from:date;
           bh=ip5PW6igBRoELerpvPl2DF77VNe5JC4vopdDoV6lpjY=;
           b=TU+Y61W432FfMIYvEmhD2r6eBDdrure+Ax+U4FIi7El3vHt2AES+mb3I2qsvvhyiAy
            CJhqO7FzQakkIkRGIWJOf4ghjrk6e6K1XIBvprPRSABVF/TvqpyFKaVc3tXJ7isW13Nh
            9Ad0Zn6/2dYjM+awXmEnzeDut5l9JB7kOApDw=
    DomainKey-Signature: a=rsa-sha1; c=nofws;
           d=gmail.com; s=gamma;
           h=cc:message-id:subject:mime-version:content-type
            :content-transfer-encoding:from:date;
           b=S8/unLzvAR7/+c1KB3PGimhO4StOsIE0r2S39oEaYLZI8jCP5F/vJg5wc/LfK2gsi3
            KypsThXRKgcjREtjmQPltOdqZhgwf+QJXW/Tg6zFaMRswgJFqig8aeY+uFddCaYTrxoc
            EtYglspCmhfJfUleh7ioCoW2w8G71rcLcN1qA=
    Received: by 10.64.184.18 with SMTP id h18mr2648302qbf.27.1227472259580;
           Sun, 23 Nov 2008 12:30:59 -0800 (PST)
    Return-Path: <[email protected]>
    Received: from 5200am2x64bit ([41.246.118.18])
           by mx.google.com with ESMTPS id p27sm3343039qbp.16.2008.11.23.12.30.57
           (version=SSLv3 cipher=RC4-MD5);
           Sun, 23 Nov 2008 12:30:58 -0800 (PST)
    Cc: [email protected]
    Message-ID: <8694729.0.1227472251250.JavaMail.NEIL@5200am2x64bit>
    Subject: My First Email
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    From: [email protected]
    Date: Sun, 23 Nov 2008 12:30:58 -0800 (PST)
    - Show quoted text -
    Hello this is a email

  • SFTP receiver error: putFile: Could not connect to remote host; Reason: Unable to open Sftp client. SshReasonCode: CHANNEL_FAILURE

    Hi,
    When we try to send file over seeburger SFTP (receiver) we are getting the error as below.
    Message processing failed. Cause: javax.resource.ResourceException: Fatal exception: javax.resource.ResourceException: >> Description: SFTP transaction error occured.>> Details: putFile: Could not connect to remote host; Reason: Unable to open Sftp client. SshReasonCode: CHANNEL_FAILURE>>SendingStatus: NOT_TRANSMITTED>>FaultCategory: COMMUNICATION_ERROR>>Retryable: true>>Fatal: true, >> Description: SFTP transaction error occured.>> Details: putFile: Could not connect to remote host; Reason: Unable to open Sftp client. SshReasonCode: CHANNEL_FAILURE>>SendingStatus: NOT_TRANSMITTED>>FaultCategory: COMMUNICATION_ERROR>>Retryable: true>>Fatal: true
    But we are able to connect through filezilla . we are able to create and delete file using the same username and password which is being used in SFTP adapter.
    we have imported the both dsa and rsa keys in SFTP partner folder in NWA. Even though we are getting same error.
    Thanks,
    Vinayak

    Hi Ram,
    we checked with network team and port 22 is open and they are able to ping to the target system.
    we checked the seeburger logs and we see EOF received from remote site error:
    Caused by: com.maverick.ssh.SshException: EOF received from remote side [Unknown cause]
    #at com.maverick.ssh2.TransportProtocol.b(Unknown Source)
    #at com.maverick.ssh2.TransportProtocol.i(Unknown Source)
    #at com.maverick.ssh2.TransportProtocol.nextMessage(Unknown Source)
    #at com.maverick.ssh.message.SshMessageRouter.d(Unknown Source)
    #at com.maverick.ssh.message.SshMessageRouter.access$000(Unknown Source)
    #at com.maverick.ssh.message.SshMessageRouter$_b.run(Unknown Source) 
    Thanks,
    Vinayak.

  • Could not connect to the smtp server

    Hi,
    I am getting following exception. What might be the reason.
    javax.mail.MessagingException: Could not connect to SMTP host: 10.48.144.150, port: 25
    at com.sun.mail.smtp.SMTPTransport.openServer(Ljava.lang.String;I)V(SMTPTransport.java:855)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(Ljava.lang.String;ILjava.lang.String;Ljav
    a.lang.String;)Z(SMTPTransport.java:156)
    Thanks
    Ashwani

    I am able to ping and telnet the server. Its my
    company's smtp serverAnd does your company have no employees that can help you diagnose network problems?

  • PHP Soap error Could Not connect to host

    Hi all, this is my first time on this forum so I hope I am not doing anything stupid.
    I have a wsdl file in my local server, when I try to access the code I get error could not connect to the host each time. I thought this was my programming mistake until I tested it on my ubuntu and windows server, It seems to be working fine on them. Is there something that I should enable some module or port ( I already have my soap extension loaded in php). Please help me out with this.
    Last edited by rohankoid (2012-04-16 05:05:22)

    Hi,
    Welcome to the    Discussions
    At one time Google(Talk) only offered the service to Google Mail accounts with either @gmail.com or @googlemail.com endings.
    Nowadays they also offer Google IDs that can then be made to work as GoogleTalk IDs.
    These are the iChat 3 instructions http://www.google.com/support/talk/bin/answer.py?answer=24076 with pics.
    In iChat 3 there was no GoogleTalk option and was added as Jabber ID and then you had to change the Server name (it presumed that it was either gmail.com as Defcom shows or googlemail.com) by taking the end of your Google Mail ID and puling it though to the Server Name box.
    In iChat 4 and 5 there is a Google ID option and this will set the Server as talk.google.com as you list.
    Google allows Port 443 to be used and the gmail.com as server name
    My Current Settings
    NOTES.
    Based on the Google Instructions your Name in iChat must match the ID you see when you login in to the Google Mail page (Or web site).
    The Mail App seems to cope with either and grab your mail for download but iChat prefers that you use the one as Listed.
    Also on your Google Account have you enabled TALK ?
    You need to do this first.
    8:24 PM Tuesday; March 16, 2010
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"

  • Could not connect to localhost

    hi
    i wonder what's wrong with the J2EE installation. i get both the server and cloudscape started up correctly. but i 'can't deploy the PetStore demo: Could not connect to localhost
    then i tried starting the J2EE tutorial, started the deploy toll: it started but the console says: Could not connect to local host
    when i call http://localhost:8000 in browser the default J2EE page appears.
    what's wrong?
    p.s.: how do i assign duke dollars to a topic? can't find anything in the FAQ ...?

    Hello? Am i the only one with this problem? Today, I reinstalled WSDP and PetStore Demo ... exact same result:
    D:\docs\Java\J2EE\petstore1.3.1>setup.bat deploy
    Buildfile: setup.xml
    init:
    deploy:
    [echo] Deploying ears ....
    [java] Could not connect to localhost
    [java] Sender object Deploytool (Main) : Could not connect to localhost
    [java] Java Result: 1
    [java] Sender object Deploytool (Main) : Could not connect to localhost
    [java] Could not connect to localhost
    [java] Java Result: 1
    [java] Sender object Deploytool (Main) : Could not connect to localhost
    [java] Could not connect to localhost
    [java] Java Result: 1
    [java] Sender object Deploytool (Main) : Could not connect to localhost
    [java] Could not connect to localhost
    [java] Java Result: 1
    [echo] The petstore application is now installed.
    [echo] Please restart your cloudscape database and the J2EE server, and the
    n point your browser to http://localhost:8000/petstore to access petstore.
    BUILD SUCCESSFUL
    Total time: 17 seconds
    what's the problem? has the current PetStoreDemo a bug? in this case: where can i find an old version of the PetStoreDemo?

  • Javax.mail.MessagingException: Not Connected

    Hi All,
    I am trying to read the message from pop.gmail.com using JavaMail API.I ma using POP3 protocol for it.
    But I got the following Exception
    javax.mail.MessagingException: Not Connected
    at com.sun.mail.pop3.POP3Store.checkConnected(POP3Store.java:279)
         at com.sun.mail.pop3.POP3Store.getFolder(POP3Store.java:261)
         at MailReceipt.connect(MailReceipt.java:97)
         at MailReceipt.mailRecieve(MailReceipt.java:62)
         at MailReceipt.main(MailReceipt.java:53)
    I got This Error at the line
    folder = store.getFolder("INBOX");
    in my program.
    Please Help me ion this regards.Thanks in Adnavce..
    Thanx & Regards
    Sandeep Verma

    Well, I've never used this API but it seems 100% clear what's wrong. And 5 seconds with Google has revealed that there's a method on that class which looks like it will address the issue.
    If you can't even read basic error messages, you should seriously question whether you should be programming.

  • Javax.mail.MessagingException: 505 Client was not authenticated

    Hi!,
    I got the following error:
    Exception in thread "main" javax.mail.MessagingException: 505 Client was not authenticated
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:507)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:312)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:168)
    at HelloMail.main(HelloMail.java:35)
    This is the code:
    To send an email I need authentification, and I include the mail.smtp.auth propertie and
    "message.saveChanges();
    Transport transport = session.getTransport("smtp");
    transport.connect("mail.xxx.com.mx","harriaga",passw);
    transport.sendMessage(message,message.getAllRecipients());
    transport.close();"
    Do you know if I am skip something.
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class HelloMail {
    public static void main(String args[]) throws Exception {
    String host="mail.xxx.com.mx"; //obviously doesn't work
    String from="[email protected]"; //sender's email
    String to ="[email protected]" ; //receiver's email
    Properties props = System.getProperties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.auth", "true");
    Session session=Session.getInstance(props,null);
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new
    InternetAddress(to));
    message.setSubject(" My Test HTML email ");
    message.setText(" Here is the content ");
    message.saveChanges();
    Transport transport = session.getTransport("smtp");
    transport.connect("mail.xxx.com.mx","harriaga",passw);
    transport.sendMessage(message,message.getAllRecipients());
    transport.close();
    Thanks for all,
    HAG.

    HAG,
    you need to create a session object passing a valid authenticator. In other words,
    MyAuthenticator auth = new MyAuthenticator ();
    Session session = Session.getInstance(props, auth);where MyAuthenticator is something like
    public class MyAuthenticator extends Authenticator{
      public PasswordAuthentication getPasswordAutentication(){
        return new PasswordAuthentication( "user", "password");
    }You obviously need to replace username and password with data valid for your e-mail account.
    Hope this helps,
    gulfi

  • Reading Inbox - javax.mail.MessagingException: Connect failed;

    I get an error message while trying to read emails by connecting to a company mailbox. The message is as follows:
    javax.mail.MessagingException: Connect failed;
    nested exception is:
         java.net.ConnectException: Connection refused: no further information
         boolean com.sun.mail.pop3.POP3Store.protocolConnect(java.lang.String, int, java.lang.String, java.lang.String)
         void javax.mail.Service.connect(java.lang.String, int, java.lang.String, java.lang.String)
         void javax.mail.Service.connect(java.lang.String, java.lang.String, java.lang.String)
         void GetMessageExample.main(java.lang.String[])
    The code is very simple and as follows:
    import java.io.*;
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class GetMessageExample {
    public static void main (String args[]) throws Exception {
    String host = "companyname.com";
    String username = "user";
    String password = "xxxx";
    try{
    // Create empty properties
    Properties props = new Properties();
    // Get session
    Session session = Session.getInstance(props, null);
    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);
    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);
    BufferedReader reader = new BufferedReader (
    new InputStreamReader(System.in));
    // Get directory
    Message message[] = folder.getMessages();
    for (int i=0, n=message.length; i<n; i++) {
    System.out.println(i + ": " + message.getFrom()[0]
    + "\t" + message[i].getSubject());
    // Close connection
    folder.close(false);
    store.close();
    } catch (Exception e) {
    e.printStackTrace();
    I have a two part question:
    1. At home I am using a dial-up connection it works when I change the settings to an email account as provided by the local ISP.
    I have tried it with both "pop3" and "imap" in
    Store store = session.getStore("pop3");
    for the company email but it does not work.
    Is this a problem with company security? Maybe firewall/proxy error? If so how do I get around it?
    2. Also, when I am in the office (LAN used to connect to Internet) I cannot even get a connection to the ISP account - similar problem or different?
    Any thoughts and help most appreciated.
    Thanks in advance,
    Mark

    It could be that the mail server is not accepting connections from the machine you are on. Have you tried using Outlook Express or the Netscape email client to connect to the server/account from the machine that is getting the failure?

  • Javax.mail.MessagingException: Unconnected sockets not implemented

    Hi,
    I am trying to get mails from mail server using IMAP.I am using Jdk 1.5.0.While I am trying to get mails, I am getting following exception.
    DEBUG: setDebug: JavaMail version 1.4.1
    DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
    DEBUG: mail.imap.fetchsize: 16384
    javax.mail.MessagingException: Unconnected sockets not implemented;
    nested exception is:
         java.net.SocketException: Unconnected sockets not implemented
         at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
         at javax.mail.Service.connect(Service.java:288)
         at com.maxis.getmail.receiveEmails(getmail.java:58)
         at com.maxis.getmail.main(getmail.java:22)
    Caused by: java.net.SocketException: Unconnected sockets not implemented
         at javax.net.SocketFactory.createSocket(SocketFactory.java:97)
         at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:225)
         at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
         at com.sun.mail.iap.Protocol.<init>(Protocol.java:107)
         at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
         at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
         ... 3 more
    Here is my code..
    String host = "host";
    String name = "username";
    String passwd = "pwd";
    java.security.Security.setProperty("ssl.SocketFactory.provider", "DummySSLSocketFactory");
    System.setProperty("javax.net.ssl.trustStore"," JAVA_HOME/jre/lib/security/cacert");
    // Get a Properties object
    Properties props = System.getProperties();
    props.setProperty("mail.imaps.ssl.enable", "true");
    props.setProperty("mail.imaps.ssl.socketFactory.class","DummySSLSocketFactory");
    //props.setProperty("mail.imaps.ssl.socketFactory.fallback", "false");
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(true);
    Store store = session.getStore("imaps");
    store.connect(host,portno ,name, passwd); // exception here
    ===================================================
    I am unable to understand where went wrong. Could someone help me ,Plz?
    Any help would be appreciated.
    Thanks.

    There were some bugs in the old instructions for socket factories. Search this forum for the details.
    But, you should just upgrade to JavaMail 1.4.3, which supports properties that better control SSL
    connections, as well as a MailSSLSocketFactory that will give you more control without having to
    write your own.

  • Error: "javax.mail.MessagingException: 505 5.7.3 Client not Authenticated

    While trying to run a program to sent sms to mobile(with airtel connection)it shows the Error:
    "javax.mail.MessagingException: 505 5.7.3 Client was not Authenticated.
    If anyone knows how to resolve this problem please reply.
    The Code is as follows:
    import java.io.*;
    import java.net.InetAddress;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class EmailSMS
    String TO;
    String FROM;
    String SUBJECT,TEXT,MAILHOST,LASTERROR;
    public static void main(String [] args) throws Exception
         EmailSMS SMS=new EmailSMS();
         SMS.setMailHost("kcsl.com");
         SMS.setTo("[email protected]");
         SMS.setFrom("[email protected]");
         SMS.setSubject("");
         SMS.setText("Hello World");
         boolean ret = SMS.send();
         if(ret){
              System.out.println("SMS was sent");
         else
              System.out.println("SMS was not sent"+SMS.getLastError());
    public EmailSMS()
         TO=null;
         FROM=null;
         SUBJECT=null;
         TEXT=null;
         LASTERROR="No methods calls";
    public void setTo(String to){TO=to;}
    public String getTo(){return TO;}
    public void setFrom (String from){FROM=from;}
    public String getFrom(){ return FROM;}
    public void setSubject(String subject){SUBJECT=subject;}
    public String getSubject(){return SUBJECT;}
    public void setText(String text){TEXT=text;}
    public void setMailHost(String host){MAILHOST=host;}
    public String getMailHost(){return MAILHOST;}
    public String getLastError(){return LASTERROR;}
    public boolean send()
         int maxLength;
         int msgLength;
         //Check to make sure that the parameters are correct
         if(TO.indexOf("mobile.att.net")>0)
              maxLength=140;
         else if(TO.indexOf("messaging.nextel.com")>0)
         {maxLength=280;}
         else if(TO.indexOf("messaging.sprintpcs.com")>0)
         {maxLength=100;}
         else maxLength=160;
         msgLength=FROM.length()+1+SUBJECT.length()+1+TEXT.length();
         if(msgLength>maxLength)
              LASTERROR="SMS length too long";
              return false;
         //set email properties
         Properties props=System.getProperties();
         if(MAILHOST!=null){props.put("mail.smtp.host",MAILHOST);}
         Session session=Session.getDefaultInstance(props,null);
         try{
              Message msg=new MimeMessage(session);
              if(FROM!=null){msg.setFrom(new InternetAddress(FROM));}
              else{msg.setFrom();}
              msg.setSubject(SUBJECT);
              msg.setText(TEXT);
              msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(TO,false));
              msg.setSentDate(new Date());
              Transport.send(msg);
              LASTERROR="Success";
              return true;
         catch(MessagingException max ){LASTERROR=max.getMessage();
         return false;}
    thanku

    Hi,
    it seems to me that you must authenticate with your smtp host. In order to do so, try following:
    While trying to run a program to sent sms to
    mobile(with airtel connection)it shows the Error:
    "javax.mail.MessagingException: 505 5.7.3 Client was
    not Authenticated.
    If anyone knows how to resolve this problem please
    reply.
    The Code is as follows:
    import java.io.*;
    import java.net.InetAddress;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class EmailSMS
    String TO;
    String FROM;
    String SUBJECT,TEXT,MAILHOST,LASTERROR;
    public static void main(String [] args) throws
    Exception
         EmailSMS SMS=new EmailSMS();
         SMS.setMailHost("kcsl.com");
         SMS.setTo("[email protected]");
         SMS.setFrom("[email protected]");
         SMS.setSubject("");
         SMS.setText("Hello World");
         boolean ret = SMS.send();
         if(ret){
              System.out.println("SMS was sent");
         else
    System.out.println("SMS was not
    t sent"+SMS.getLastError());
    public EmailSMS()
         TO=null;
         FROM=null;
         SUBJECT=null;
         TEXT=null;
         LASTERROR="No methods calls";
    public void setTo(String to){TO=to;}
    public String getTo(){return TO;}
    public void setFrom (String from){FROM=from;}
    public String getFrom(){ return FROM;}
    public void setSubject(String
    subject){SUBJECT=subject;}
    public String getSubject(){return SUBJECT;}
    public void setText(String text){TEXT=text;}
    public void setMailHost(String host){MAILHOST=host;}
    public String getMailHost(){return MAILHOST;}
    public String getLastError(){return LASTERROR;}
    public boolean send()
         int maxLength;
         int msgLength;
         //Check to make sure that the parameters are correct
         if(TO.indexOf("mobile.att.net")>0)
              maxLength=140;
         else if(TO.indexOf("messaging.nextel.com")>0)
         {maxLength=280;}
         else if(TO.indexOf("messaging.sprintpcs.com")>0)
         {maxLength=100;}
         else maxLength=160;
         msgLength=FROM.length()+1+SUBJECT.length()+1+TEXT.leng
    h();
         if(msgLength>maxLength)
              LASTERROR="SMS length too long";
              return false;
         //set email properties
         Properties props=System.getProperties();
         if(MAILHOST!=null){props.put("mail.smtp.host",MAILHOST
    Session
    session=Session.getDefaultInstance(props,null);
         try{     // Get a Transport object to send e-mail
                   Transport bus = session.getTransport("smtp");
                   // Connect only once here
                   // Transport.send() disconnects after each send
                   bus.connect(host, username, password);
              Message msg=new MimeMessage(session);
    if(FROM!=null){msg.setFrom(new
    w InternetAddress(FROM));}
              else{msg.setFrom();}
              msg.setSubject(SUBJECT);
              msg.setText(TEXT);
              msg.setRecipients(Message.RecipientType.TO,InternetAd
    ress.parse(TO,false));
              msg.setSentDate(new Date());// Send message
              bus.send(msg);
              bus.close();
              LASTERROR="Success";
              return true;
    catch(MessagingException max
    ){LASTERROR=max.getMessage();
         return false;}
    thankuGood luck

  • Hello, javax.mail.MessagingException: Unknown SMTP host:

    Hello,
    I am trying to send a mail and use a smtp Server which is located on the internet. I am however behind a firewall and am getting the following exception being thrown:
    javax.mail.MessagingException: Unknown SMTP host:
    This implies that I need to provide some settings for my proxy server. I though to solve this problem I could do the following:
    System.getProperties().put("proxySet", "true");
    System.getProperties().put("http.proxyHost", proxyHost);
    System.getProperties().put("http.proxyPort", proxyport);
    This however does not solve me problem as I still get the above exception. Could someone please give help me. Any suggestions,solutions or ideas as to what the problem might be would be appreciated.
    Thanks much,
    Alex.

    HTTP is not SMTP.
    Your proxy server no doubt allows your system to send
    HTTP traffic to and from the outside world, and using
    that code you posted would allow Java classes to do
    that as well. But HTTP is not SMTP. Ask the network
    people who configured your proxy server if it can act
    as an SMTP proxy, and if so what you have to do to
    use it in that way.Thanks much for your reply. I am however a little confused. Could you explain to me exactly what an SMTP proxy is/does.
    Thanks much,
    Alex.

Maybe you are looking for