• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending email from java code in eclipse

 
Neha Sud
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




 
Tim Moores
Saloon Keeper
Posts: 3262
54
  • 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.
 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • 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
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • 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
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!