This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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?
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
posted
0
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.
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"); }
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
posted
0
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");
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
posted
0
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.
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
posted
0
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);
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.