• 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

Connect to SMTP server

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How does one connect to SMTP server to send email?
I'm getting "recipient address rejected: access denied" and I think its because I'm not specifying login ID and password.
When I look in the JavaMail api documentation I see information about how to connect for the purposes of getting pop3 or imap email
i.e.


I tried this code but it didn't work. For purposes of writing email how should I connect to the SMTP server with ID and password.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at Authenticating Yourself section at JavaMail Tutorial
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

I looked at that documentation and coded up an attempt, but I'm getting an authentication error.

The "how to authenticate yourself" documentation is again tailored to connecting to pop3. My problem is that I need an authenticated connection to the SMTP server so that I can write email.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That example should work for smtp too. What do you see in the logs? And you will also have to add the following, in addition to the other properties:

 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that information.

I'm writing a Java App to do this so I don't have (app server) logs to look at. I set the property you suggested (smtp auth true) and I started to get email written (instead of getting address rejected: access denied).
Whats odd is that I am still getting

javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at qflexAlert.emailESBsupp(qflexAlert.java:57)
at qflexAlert.main(qflexAlert.java:17)

but my email is still written out by the SMTP server. I don't understand this.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

store.connect("smtpauth.fairpoint.net","roetow@fairpoint.net","5540");



Instead of this, try using


[ July 07, 2007: Message edited by: Jaikiran Pai ]
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have modified the code per your suggestion (re: JGuru's JavaMail tutorial) and currently I am running with store.connect().

store.connect () is the instruction which is kicking the exception - authentication failure.

I think its odd that store.connect kicks an exception which I log and ignore and then my attempt to write email succeeds.

I think I'll remove the store.connect() code and try it that way. Maybe it will work with just the userID and pwd in the props.
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Jai,

Thank you so much for your help. I finally got this program to work OK (without a store.connect().

 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great!
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am replying to this mail even though its been ages since last reply. The below code is tested and does work. Make sure that firewall allows the required ports through.

Best of luck
Sanjay Mistry

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic