• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Sending email from java code in eclipse

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i am using JDK 1.8 and Eclipse Mars IDE .
I have added Javamail api in build path and also tried to enter proxy details in Window-> Preference-> Network settings-> Proxy settings. In proxy setting , i set proxy ip and other details to connect to internet.But when i run below code, exception is thrown. Please guide me , how to set up smtp server in eclipse so that i could send mail from java code in eclipse.

I run this sample code to send email from my system:

But this code gave exception




 
Saloon Keeper
Posts: 6588
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a mail server running on port 8090 of that IP address? If not, and you've never set up a mail server, it's probably easier to start by using an existing server, like Gmail.

If you're set on running your own mail server, check out Apache James for a start.
 
Marshal
Posts: 3180
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code specifies that the host is 172.31.1.6:8090, and by default port 25 is being used.


Set the mail.smtp.port property to specify the port:
        properties.put("mail.smtp.port", 8090);
 
Neha Sud
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for quick response!!

I made change in default port setting as highlighted by Ron  and code is running but no result is coming on console now.



I suppose this line is not executing since next  line after this send message does not print text on console. So i suppose code enter into certain deadlock as eclipse shows application is running but no response is recorded on console.

Also , i have few other doubts in this sample code like , i have not entered password for mail authentication  So how this code works on authentication part. Also, IP  172.31.1.6
is proxy address of network..SO this also needs to bypassed to connect to gmail and send mail but this code doesn't ask for that credentials also.. SO this code will work then.

I found gmail alerted me when i tried to run this code by send warning mail in inbox but didn't receive email from java code..SO how to tackle this.
 
Ron McLeod
Marshal
Posts: 3180
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran this same code substituting my own email server and To/From addresses, and it worked fine.

I don't understand the relationship between IP address 172.31.1.6 port 8090 and Gmail.  If you are trying to send through Gmail, why don't you connect directly to smtp.gmail.com?

Also, if you will be using Gmail, it is going to require password authentication and a connection over TLS (smtps).
 
Neha Sud
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Rob!!

Actually, being new to topic , it took time to understand concepts that were highlighted. I made few changes in code like added authentication and gmail settings updated, lowering down security of my gmail account so that my device could connect to gmail. Thankfully these changes worked and code is working at my end too.

Updated code



Thanks again for explanations of queries!!
 
Ron McLeod
Marshal
Posts: 3180
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great to hear that you got it going and thanks for sharing your solution.
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic