• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Apache Commons - Email -Sending to server fails

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have just started learning the apache commons libraries, and specifically, today I wanted to write a simple program that sends an email from myself to myself, using classes and functions found in org.apache.commons.mail. Unfortunately, when I execute the program, regardless of weather I'm using port 465 or 587, I continue to get the following error:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.mail.yahoo.com:465
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)


Thanks in advance for any help in this, and my apologies for any digital faux-pas or whatnot.  
Here is the relevant block of code:

 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Knowing that it failed is only the first step in your journey. The next step is to find out why it failed -- there could be many different reasons. And to find that out, it would help to see the stack trace for the exception.

If you have that, then do post it here for people to examine. If you don't, then you need to modify your code to produce a stack trace. (In fact your code should always be written so the stack trace is available for this kind of research.)
 
Master Rancher
Posts: 180
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for the wall of text - I've wrote it rather drunk and just wrote down anything that came into my mind as I wrote it - to any mods: feel free to cut it down

Well, at least if you're using the code as posted there's one major issue I (as someone manging his own mail server since early 2015) spots instant: you try to use some @yahoo.com profile to send from some @gmail.com mail - this doesn't work for a couple of reasons:

1) using your @yahoo.com account requires you to have your mail from that address - you just can't say "oh yea, this mail is from my @gmail.com address" while using your @yahoo.com account - if you're using a @yahoo.com account its FROM has to be that @yahoo.com account - otherwise the yahoo servers most likely already reject your mail as it contains a non matching FROM address

2) sending a mail from your own account to yourself can be considered spam - it just doesn't make sense to connect to your mail providers mail server and drop in a mail comming from yourself to be send to yourself - that's  most likely either some developer action or an attack try to figure out your credentials - if you want to test always send FROM your account TO some other to at least make it look like a legit mail to be send from you to someone else

3) although I have lots of experience running my own mail server and using the JavaMail API, I never was a fan of apache commons - as, although they have quite a large library of common used funcationality it always require to get the whole lib involved - don't get me wrong, I'm not against using libs and (re-)use codes proven to work - but it's just a personal choice as I don't like it to use in that way

4) as already mentioned: no matter if you use some logging or just plain "print to console", but at least in my personal opinion every catch-block should contain a call to printStackTrace() somewhere - as it can be not just helpful but required to firgure out what actually went wrong and caused the exception in the first place
sure, when dealing with GUI it often throws some nonesense NullPointerException of the EDT maybe hard to trace from where it really was called in the first place - but it at least gives you some hint where to start search instead of just "there was some unknown issue while completing that action"

5) in addition to all that, as someone taking care of his own mailserver, I know that just "sending an email from within some lines of java" can get you at least the same sort and amount of headaches as try to use PHPs mail() function
just as an example: I recently cleanly installed my root serer with the recent version of the distribution I use (opensuse leap 15.2) - and as I juse apache James as my mailserver I have set up sendmail as what's known as a "nullclient" to just pass any mail dropped in by an invocation of sendmail binary to my james to handle it - and as this was a clean setup I forgot to correctly set my hostname - which for whatever reason locked up sendmail in quite some delay which ended up in the simple mail() script in PHP to block for even longer - to track down that issue it require me to try what's apache doing from the terminal and to check the system logs to spot the line "hostname not set"
same could be true for your code: for what ever low-level reason it doesn't work the way as when you use thunderbird to send a mail - this can require to get as low-level as to use wireshark to inspect the network packets

6) I don'T know from what machine and what type of connection you try to run that code - but as there'Re a lot of common anti-spam mechanisms in place when you try to run that code from your local machine using your private ISPs connection it could get rejected just cause you connect from a source known to be used by an ISP for personal connections - that's some issue you have to deal with when you try to host your mail server not on a dedicated machine in some datacenter but from your home connection

7) although nothin to do with your mail stuff - but with your GUI code: do NOT call time consuming taks from within the EDT - have a look at https://coderanch.com/t/738589/java/measure-writer-progress-JProgressBar for why not to do what you'Re doing and how to do it better

I could go on with at least another 5-10 causes for "why my mail doesn't get to its target" - but without the full stacktrace and some more information I guess it'll be hard to figure out
 
Marshal
Posts: 3708
523
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Zimmermon wrote:... when I execute the program, regardless of weather I'm using port 465 or 587, I continue to get the following error ...


I don't think there is any problem with the code - I ran the code after changing the mail server and credentials and the message did get delivered.


The problem that you are probably seeing is that Yahoo is blocking your app from sending mail for security reasons.  I know with Google (what I tested with), that the account needs to be specifically be configured for less secure app access to be able to send message from a third-party app like what you have.  Even if you do get it to work, you may find that your emails may get blocked by the receiving email domain or the recipient's email client because it may be deemed to be SPAM or look suspicious.
 
reply
    Bookmark Topic Watch Topic
  • New Topic