This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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

not able to send mail using google smtp

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below attached is my code and error.


ERROR:


Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: [EOF]
       at SendEmail.main(SendEmail.java:57)
Caused by: javax.mail.MessagingException: [EOF]
       at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
       at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:917)
       at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:417)
       at javax.mail.Service.connect(Service.java:310)
       at javax.mail.Service.connect(Service.java:169)
       at javax.mail.Service.connect(Service.java:118)
       at javax.mail.Transport.send0(Transport.java:188)
       at javax.mail.Transport.send(Transport.java:118)
       at SendEmail.main(SendEmail.java:52)
 
Marshal
Posts: 25814
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sajan, welcome to the Ranch!

What you posted there looks more or less like the sample code I've seen elsewhere for using Gmail to send messages. I haven't examined it in detail, though. The only problem I see is, I wouldn't expect to be able to use Gmail to send messages from some other domain (like abcd.com). I would expect the authentication to fail, for one thing.

However the error message you posted isn't quite what I would expect. It looks more like you can't make a connection to Gmail's SMTP server, maybe.
 
Sajan Shakya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the same code is working fine for other servers, i can telnet to localport 25 as well as 587, the problem is with only one server. Thanks in advance
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Possibly it's a firewall issue. Can you have your infrastructure guys check it out?
 
Marshal
Posts: 3181
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just ran your code and it worked as expected.

Try adding session.setDebug(true) and compare the output against what I saw:
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just ran the code and it not worked as expected.
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: "myhost", port: 25;
 nested exception is:
java.net.ConnectException: Connection timed out: connect
 
Rob Spoor
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a machine called "myhost" that has a mail server running? Because that's not Google's SMTP server.
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
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