wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes problem sending mail to other domains Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "problem sending mail to other domains" Watch "problem sending mail to other domains" New topic
Author

problem sending mail to other domains

Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Hi,

I have a problem sending mail to other domains. The error i got is

DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException:
C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.providers
(The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name:
{com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider
[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems,
Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,
smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.
mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.
imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.
POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.
POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.
IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.
IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=
javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,
Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider
[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems,
Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,
Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.
sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.
Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc],
pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,
Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.
mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\
lib\javamail.address.map (The system cannot find the file specified)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.
mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
java.lang.Exception
at MailerBean.sendMail(MailerBean.java:97)
at MailTest.callSendMail(MailTest.java:66)
at MailTest.main(MailTest.java:94)


the code used is ----

props = System.getProperties();
props.put("mail.smtp.host", <host> ;
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.user", "ganesh");
props.put("mail.smtp.password", <password> );
props.put("mail.debug", "true");

// create some properties and get the default Session
Session session = Session.getInstance(props, null);



Help me out please.

thanks in advance
Ganesh
Abhijith Prabhakar
Ranch Hand

Joined: Dec 29, 2006
Posts: 56
I think you need activation.jar and mail.jar for sending mail. Are you sure that you have put the jar's in the build path.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Abhijith Prabhakar:
I think you need activation.jar and mail.jar for sending mail. Are you sure that you have put the jar's in the build path.


Assuming you can send email to addresses in one domain, its unlikely this is the problem. You seem to be masking the exception message; what's happening in MailerBean? Presumable its not the Session.getInstance() line that causes the problem?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Dear Abijith,

Thanks for your reply.
I have put the mail and activation jar and also given the path.
It is working if i send to my company mail ids, but if i send any mail to
hotmail or yahoo it is saying error.

Hope this helps you to guide me.


Thanking you in advance,
Ganesh


---------------------
Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Dear Paul,

Thank you for your reply, below is the code i used
It is working if i send to my company mail ids, but if i send any mail to
hotmail or yahoo or other mail ids it is saying error.


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

public final class MailerBean extends Object implements Serializable {

/* Bean Properties */
private String to = null;
private String from = null;
private String cc = null;
private String bcc = null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;



/* Setter Methods */
public void setTo(String to) {
this.to = to;
}

public void setFrom(String from) {
this.from = from;
}


public void setCC(String cc)
{
this.cc = cc;
}

public void setBCC(String bcc)
{
this.bcc = bcc;

}

public void setSubject(String subject) {
this.subject = subject;
}

public void setMessage(String message) {
this.message = message;
}
/* Sends Email */
public void sendMail() throws Exception {



if(!this.everythingIsSet())
{
throw new Exception("Could not send email.");
}


props = System.getProperties();
props.put("mail.smtp.host", "mail.andreconsultancy.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.user", <mail id> ;
props.put("mail.smtp.password", <password> );
props.put("mail.debug", "true");

// create some properties and get the default Session
Session session = Session.getInstance(props, null);







try {

MimeMessage message = new MimeMessage(session);


Calendar rightNow = Calendar.getInstance();

message.setSentDate(rightNow.getTime());

message.setRecipient(Message.RecipientType.TO, new InternetAddress(this.to));

if(cc != null)
{
message.setRecipient(Message.RecipientType.CC, new InternetAddress(this.cc));
System.out.println("CC set method of mail class");
}
if(bcc != null)
{
message.setRecipient(Message.RecipientType.BCC, new InternetAddress(this.bcc));
System.out.println("BCC set method of mail class");
}


message.setFrom(new InternetAddress(this.from));

message.setSubject(this.subject);

message.setText(this.message);



Transport.send(message);



} catch (MessagingException e) {
throw new Exception(e.getMessage());
}

}


/* Checks whether all properties have been set or not */
private boolean everythingIsSet() {
if((this.to == null) || (this.from == null) ||
(this.subject == null) || (this.message == null))
{
return false;
}


if((this.to.indexOf("@") == -1) ||
(this.to.indexOf(".") == -1))
{
return false;
}

if((this.from.indexOf("@") == -1) ||
(this.from.indexOf(".") == -1))
{
return false;
}


return true;
}
}


Error dissplayed is
-----------------------


################## B 4 ###################
################## B 4 sendmail() ###################
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.address.map (The system cannot find the file specified)
BCC set method of mail class
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
java.lang.Exception
at MailerBean.sendMail(MailerBean.java:124)
at MailTest.callSendMail(MailTest.java:53)
at MailTest.main(MailTest.java:74)
################## 1/2 ter ###################



Hope this helps you to guide me.


Thanking you in advance,
Ganesh
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Its still not that easy to say, since this:

is not a very good way to handle exceptions. Why re-throw the MessagingException as an Exception? Plenty exceptions do not include a message, so you might end up with an empty message that is difficult to solve.

That being said, I'm guessing you are probably being stopped from relaying messages to different domains by your SMTP server. Get the stack trace from your MessagingException and it should at the very least include the SMTP code that prevented you program from working.
Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Dear Paul,

Thanks for your reply,
As told by you when i print stack trace this is what the error displayed


DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.address.map (The system cannot find the file specified)
BCC set method of mail class
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
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 MailerBean.sendMail(MailerBean.java:119)
at MailTest.callSendMail(MailTest.java:53)
at MailTest.main(MailTest.java:74)


------

I have give the details as
props.put("mail.smtp.host", "mail.andreconsultancy.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.user", "ganesh@andreconsultancy.com");
props.put("mail.smtp.password", <password> );
props.put("mail.debug", "true");

Please do guide me.

Thanking you very much,
Ganesh
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ok, so your MessagingException is actually an AuthenticationFailedException. So it looks like you need to authenticate to send messages. Try replacing your Transport.send() line with something like:
Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Dear Paul,

Thank you very much for your continued guidance
I did as you have told

t = session.getTransport("smtp");
t.connect("70.86.9.114","ganesh@andreconsultancy.com", <pwd> ;
t.sendMessage(message, message.getAllRecipients());

But still the same error persists


DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_09\jre\lib\javamail.address.map (The system cannot find the file specified)
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 "70.86.9.114", port 25, isSSL false
220-AILS1.esandhai.com ESMTP Exim 4.63 #1 Wed, 31 Jan 2007 05:46:51 -0600
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
DEBUG SMTP: connected to host "70.86.9.114", port: 25

EHLO ws1
250-AILS1.esandhai.com Hello ws1 [125.22.225.27]
250-SIZE 52428800
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<ganesh@andreconsultancy.com>
250 OK
RCPT TO:<to_gunsa@hotmail.com>
550-(ws1) [125.22.225.27] is currently not permitted to relay through this
550-server. Perhaps you have not logged into the pop/imap server in the last 30
550 minutes or do not have SMTP Authentication turned on in your email client.
RCPT TO:<ganeshyadhav@yahoo.com>
550-(ws1) [125.22.225.27] is currently not permitted to relay through this
550-server. Perhaps you have not logged into the pop/imap server in the last 30
550 minutes or do not have SMTP Authentication turned on in your email client.
DEBUG SMTP: Invalid Addresses
DEBUG SMTP: to_gunsa@hotmail.com
DEBUG SMTP: ganeshyadhav@yahoo.com
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 Reset OK
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550-(ws1) [125.22.225.27] is currently not permitted to relay through this
550-server. Perhaps you have not logged into the pop/imap server in the last 30
550 minutes or do not have SMTP Authentication turned on in your email client.
;

-----------------

Hope this give you details to find out where i have done the mistake.

Awaiting your valuable reply.


thanks,
Ganesh
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 Reset OK
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550-(ws1) [125.22.225.27] is currently not permitted to relay through this
550-server. Perhaps you have not logged into the pop/imap server in the last 30
550 minutes or do not have SMTP Authentication turned on in your email client.
;

Things to check:
  • Are your authentication details OK? Username and password correct?
  • Does this server allow clients to relay messages to yahoo and hotmail? Its possible your server admins just don't allow this full stop (speak to them).


  • What a 550 means is that the SMTP server doesn't let you relay a message from a specific address to another. Normally SMTP servers are configured to allow you to send emails from addresses within your domain to other addresses in your domain or outside it. Is andreconsultancy.com a domain your server allows you to send emails from (again, speak to your server admin).
    Ganesh Chandrasekaran
    Greenhorn

    Joined: Nov 14, 2000
    Posts: 22
    Dear Paul,



    Thank you very much.
    It is working now. After adding what you said

    -----
    message.saveChanges();
    t = session.getTransport("smtp");
    t.connect("70.86.9.114","ganesh@andreconsultancy.com", "test");
    t.sendMessage(message, message.getAllRecipients());

    ------
    mistakenly i have removed the quote for "true" in this line which
    made the program continue to give the error
    props.put("mail.smtp.auth", true);




    Once again I thank you,


    Thanks,
    Ganesh
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    You are welcome. Glad you got this sorted.
    Marcus Hathaway
    Ranch Hand

    Joined: Jun 07, 2005
    Posts: 89
    Hi,

    This problem describes exactly the problem i am having and seem so far unable to resolve.

    My email class works fine about 80% of the time...but on some smtp.hosts i get an exception:

    javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:306)
    at javax.mail.Service.connect(Service.java:156)

    I've followed the excellent advice Paul gives above in changing the way the message is sent and this did eliminate some transport exceptions.

    However i get the above exception from the line t.sendMessage(msg, msg.getAllRecipients());

    Has anybody got any suggestions or pointers on this? Its been an ongoing problem of mine for ages now and i'm not sure what else to try

    My code (which works on the majority of emails sent out by different hosts) is:

    Any tips would be greatly appreciated!

    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    I'd check which domains do not allow your emails out, and I'd check whether they don't allow you to connect, or to relay the email etc. Turn on Java Mail's debugging and you'll get the complete SMTP conversation. And speak to the administrator of the SMTP servers you are having trouble with.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: problem sending mail to other domains
     
    Similar Threads
    SMTP(Simple Mail Transer Protocol)
    sun.security.provider.certpath.SunCertPathBuilderException
    sending mail using javamail and gmail smtp
    Unknown SMTP host exception in java mail.
    com.sun.mail.smtp.SMTPSendFailedException: 451 4.7.1 Please try again later