• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java Mail API Help

 
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

As always, many thanks for anyones help or advice.

I am trying to send email from my Servlet.



I have:



In catalina.policy i have:



No exception or error is being thrown, but i do not get an email sent to my address.

Im not sure why this isn't working.

I am using java 1.6, so i shouldn't need anything mnore than mail.jar.

Regards, Sam
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call session.setDebug(true) and check your output / log files. You'll be able to see exactly what JavaMail is doing.
 
Sheriff
Posts: 28371
99
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
I would suggest that you test sending of e-mail in a plain old Java application first, like a small command-line program which does just that and nothing else. Tomcat and Servlets aren't really easy to use for basic testing.

And make sure that your setup agrees with the assumptions that I see from your post:

1. You are running an SMTP server on the same computer where the code is running.

2. It is listening at port 25 (which is the default port for SMTP).

3. It doesn't require authentication.

4. It is configured so that it can relay e-mails which claim to come from a different domain (gmail.com in your case).

You should also become conversant with the administrative functions of that SMTP server, so that you can tell whether it has delivered an e-mail successfully. Or if it isn't your server, you should enlist the help of its administrator.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Many thanks for your help.

I think the problem could be my local host sending. I thought i could just use googles smtp server. I did used to run postfix... but it was such a pain to administer, i ditched it.



So you cant send email from java, without the ocal machine running an SMTP server?


Regards, Sam
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess if i had host as "smtp.gmail.com"



Regards, Sam
 
Paul Clapham
Sheriff
Posts: 28371
99
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
Sure you can use the Gmail server. Have a look at the JavaMail FAQ for the issues involved with doing that, including how to do the authentication.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Massive thanks!!! Got it all working great.



Many thanks for everyones help.

Regards, Sam

(Edit: Hide password -- Paul C)
(Edit: and email address -- Rob)
 
Paul Clapham
Sheriff
Posts: 28371
99
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
Working now? Great!

However...



You didn't get this from the JavaMail FAQ, did you? Because there's no such property in JavaMail.

There's nothing wrong with using non-existent properties, in the sense that they don't cause the program to break. But it's unhelpful to future maintainers of the code because it gives them extra work to find out that they do nothing. Likewise it's unhelpful to post such code on the web because then unwary students will copy the code elsewhere, compounding the problem.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah thanks Paul Clapham, no i didnt. tbh, it was a mix of googling / forums / mail API reading. I started looking prior to reading your previous response.

Many thanks for your help, much appreciated!

Out of interest - how safe is storing my email pwd as compiled code, on tomcat?

I'm not that happy with it, or am i just paranoid?

Regards, Sam
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends - do you trust your sys admins? If not, I suggest to get hosting elsewhere.
 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim Moores

well, currently its just running locally (on Opensuse) - so i trust me.

the client-side is actually a swing desktop application, and i guess in the future it would have to use either the chosen hosts mx servers, or my own running next to tomcat. But thats a long way off (and this is only a peronsal project, so whether i ever get to that point is in question).

thanks again for your help.

I more wondered if it was possibleto hack a servlet to get info like that.

Regards, Sam
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you somehow obtain physical access to the servlet's class/jar file then it's easy to decompile it and retrieve such information. But I'd argue that once someone has access to those files, and is bent on causing trouble, you have much bigger things to worry about.

In general, you should keep the connection details out of the Java code, maybe in a properties file, just like you'd do for DB and logging properties.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic