• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

My Application is not sending mail to external servers

 
Ranch Hand
Posts: 155
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys I am trying to send Mail from My server to other servers such as Yahoo and Gmail. Apparently, My application is working pretty fine when I send an Internal mail (to the local server). Can anyone please tell me what I need to do with my code so that the Application is able to send mail outside the local host server? Here is my code
THIS IS THE MAIN CLASS




AND THIS IS THE AUTHENTICATION CLASS
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stanley,

When you say

My application is working pretty fine when I send an Internal mail (to the local server).

can you clarify what you mean by local server?

Is this a server running on your machine or otherwise in a test environment or is this the same server you use from an email client? To ask it a different way, can you connect an email client such as Thunderbird to the "local server" and send an email that reaches the outside your intranet? If not, then that is the first place you should lok at as this could likely be a configuration issue in that the local server does not handoff to a provider (such as your ISP) "linked" to the internet.

If you can initiate an email via a client that gets to the internet, then please review the logs of the mail server and if you see any sort of error messages or things that do not look right post them for review. Also, please clarify your code - it could be my browser, but when I look at your main class, I do not see the end of the code. When you send the email, it would be good to clarify that the code is set up to report exceptions properly (i.e. is there an empty catch block that could be masking an Exception).
 
Stanley Mungai
Ranch Hand
Posts: 155
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian, when I say Local server I mean that it can send to any E-mail address from My Host mail server 196.201.227.106 but won't send to other hosts such as G-mail, Yahoo mail and the like. Just sends to the Local host.
 
Brian Burress
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fair enough. So when you connect a client like Thunderbird to your local server and send an email to yahoo or gmail, does it get routed to the external email properly?

If not, then you'll need to look at the server configuration/log.
 
Stanley Mungai
Ranch Hand
Posts: 155
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Brian Thank you I will do that. Just wanted to confirm that there is nothing wrong with that code.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to check "Is there any authentication required for the SMTP Mail Server", specified in code.

If yes then try to put

Transport trans = ses.getTransport("smtp");

trans.connect("<SMTP Host>","<SMTP Auth User Name>","<SMTP Auth Password>");

for more details please follow the link

http://www.webdeveloper.com/forum/showthread.php?t=143496
 
Stanley Mungai
Ranch Hand
Posts: 155
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am posting this because of People that may have the Same Problem as I had. It was not a problem of the server but a problem with the code. I may not be able to explain fully but this code here sends mails to wherever you want it to go unlike the one I had posted earlier that only sends to the local host. The main clas looks like:



The authentication Class Remains Largely the same and looks like this:
 
Piyush Doraya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dear Stanly,
With the mentioned code suggestion following error observed on the console:



Out put observed on console

DEBUG: JavaMail version 1.4.4
DEBUG: failed to load any providers, using defaults
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.,1.4.4], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.4], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,1.4.4], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.
un.mail.pop3.POP3SSLStore,Sun Microsystems, Inc.,1.4.4], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc.,1.4.4], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc.,1.4.4]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc.,1.4.4], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc.,1.4.4], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc.,1.4.4], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc.,1.4.4], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPT
ansport,Sun Microsystems, Inc.,1.4.4], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc.,1.4.4]}
DEBUG: failed to load address map, using defaults
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.4]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "<SMTP Host>", port 25, isSSL false
220 dcdelexc01.Eichergroup.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.1830 ready at Tue, 6 Mar 2012 13:24:55 +0530
DEBUG SMTP: connected to host "<SMTP Host>", port: 25

EHLO <Server Name>
250-<Server Name> Hello [<Server Name>]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "OK", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
ZG9ub3RyZXBseQ==
334 UGFzc3dvcmQ6
cEBzc3cwcmQ=
235 2.7.0 Authentication successful.
DEBUG SMTP: use8bit false
MAIL FROM:<yourname@hostname> AUTH=donotreply
250 2.1.0 yourname@hostname....Sender OK
RCPT TO:<yourname@gmail.com>
250 2.1.5 yourname@gmail.com
DEBUG SMTP: Verified Addresses
DEBUG SMTP: yourname@gmail.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;



Do you have any resolution about the exception.


 
Stanley Mungai
Ranch Hand
Posts: 155
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pirush Doraya. Check that you have activation.jar on your class path please.
 
Piyush Doraya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stanley Mungai wrote:Pirush Doraya. Check that you have activation.jar on your class path please.


Files are present in the classpath. Same code working fine when i am trying to send mail to local user i.e. on local domain. But gives error when trying to send same mail to any user in gmail, yahoo domain.
 
Stanley Mungai
Ranch Hand
Posts: 155
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well am Using the same code with No errors. Try the Following,

Check that Authentication Username and Password are correct, or
Delete all the imports and Fix them back automatically By Right Clicking on the Code the fix Imports.
Check the Server settings.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic