Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-mails using Tomcat?

Status
Not open for further replies.

pisth

Programmer
Mar 18, 2003
43
US
Hell0,
I have a program written by someone else which does some calculations
and e-mails the results to the user. The program was running good
on a Linux server.

Now the program was transferred from Linux to Windows. However the
E-mail functionality is not working and the results are not send to
anyone. A Tomcat server is being used. Can we e-mail the results to the
user using a tomcat server.

If so how do we do that?. (or) would there be a better and
easy way to do it rather than e-mails...(the program also takes some
considerable amount of time to calculate the results...)

I need to get this fixed at the earliesstttttt as i am running short
of time and deadlines.

Kindly let me know how do i do it?

Thanks!

Regards,
Karthik.
 
When on the linux box, how was your (I guess though you don't say) servlet or JSP sending the mail. Was you using a JavaMail, or other java written program, or shelling out to linux and using something like sendmail ?

If the former, then can you access port 25 ? What are the permissions or priviledges like to connect to that port ?

If the latter, then I'd rewrite the sendmail-type program in pure java using JavaMail ...

What error messages are you seeing, what to the Tomcat logs say ?

Ben
 
Hell0 Ben,
It was a JSP that was sending an e-mail. I think it is written in something like send mail. Like...the error messages:

^
msgsend.java:157: cannot resolve symbol
symbol : variable InternetAddress
location: class msgsend
InternetAddress.parse(cc, false));
^
msgsend.java:159: package Message does not exist
msg.setRecipients(Message.RecipientType.BCC,
^
msgsend.java:160: cannot resolve symbol
symbol : variable InternetAddress
location: class msgsend
InternetAddress.parse(bcc, false));
^
msgsend.java:170: cannot resolve symbol
symbol : variable Transport
location: class msgsend
Transport.send(msg);
^
msgsend.java:178: cannot resolve symbol
symbol : class Store
location: class msgsend
Store store = null;

i get something like this...like abt 70 errors when i compile the program. tomcat does not say anything. when i press the submit button(to tell the server that send me an e-mail after inputting the e-mail address...) the tomcat just shuts down.

am i clear.?..can u help?

Thanks

Regards,
Karthik.
 
It sounds like a CLASSPATH problem. From the error >>>

msgsend.java:160: cannot resolve symbol
symbol : variable InternetAddress
location: class msgsend
InternetAddress.parse(bcc, false));

It looks like in your class 'msgsend', it cannot find classes in the packages ::
javax.mail
javax.mail.internet

Find the jar (maybe mail.jar, from memory) and add it to your CLASSPATH

Ben
 
Hell0,
When I press the submit button requesting to send me an e-mail, these are some of the exceptions that are generates in the tomcat web server.

javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:

javax.mail.SendFailedException: 550 5.7.1 Unable to relay for kcisfine@hotmail.com


at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at com.bioscience.SliPsi.SliPsi.sendMail(SliPsi.java:159)
at com.bioscience.SliPsi.SliPsi.ProcessInput(SliPsi.java:75)
at org.apache.jsp.SliPsi_jsp._jspService(SliPsi_jsp.java:101)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

My Questions are: Well. I have installed j2sdk1.4.1_02 and a tomcat swerver version 4.1.24 is running. However i did not install anything for the e-mails and stuff. do i need to download something from the web for e-mails to work in java?. and...if so...what do i download...can you give me the link...and if i download it...where do i place it?...

Waiting for a reply.

Thanks Very Much!

Regards,
Karthik.
 
Looking up 'SendFailedException' on the Sun site docs illuminates this exception's causes.

Can you post the relevant code so we can check you've built your addresses and server IPs properly ...
 
If you still can't get it to work, go back to a simple standalone test - the below works ...

import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;

public class SendMail {
public static void main(String args[]) {
Properties props = System.getProperties();
props.put("mail.smtp.host", "mail.hotmail.com");

Session session = Session.getDefaultInstance(props, null);

try {

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("me@somewhere.com"));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("someguy@hotmail.com", false));
msg.setSubject("Hello !");
msg.setText("Hello there");
msg.setHeader("X-Mailer", "Test-Send");
Transport.send(msg);
} catch (AddressException ae) {
ae.printStackTrace();
} catch (MessagingException me) {
me.printStackTrace();
}
}
}
 
Hell0,
Thanks very much for all your help and replies.

I have a few more questions.

Well. It was a class path problem. I set the classpath for all and now the program compiles without any errors.
However there were exceptions getting generated when I used to run the program. Now I installed a component called JAMES from the Jakarta website and now no exceptions were getting generated.

My Questions are:
To my surprise, I received one e-mail(the o/p of the program) which I am supposed to get on my e-mail. However when I run the program again I dont get any e-mails. I had tried running the program yesterday...no e-mail was generated...now I tried it...using a different e-mail address...however the e-mail got send to the address i specified yesterday. So, is the program working??...(or) am i doing anything wrong?. maybe the prgm takes a lot of time to calculate or something?(can you clarify why i got an e-mail the first time...and not any other time)...i am waiting for the results as i just put my e-mail addresses an hour back.

1 more question:
String from = "karthikch@hotmail.com";
String to = email;
String subject = "Results_for_" + GI; (GI is a number)

is the above code correct?
My Question is:

props.put("mail.smtp.host","host");

WHAT IS THE NAME OF THE HOST?. I AM NOT ABLE TO FIND WHAT THAT IS?...how do i find it?...can i do ipconfig and write watever i get therE?.

can it be an "ipaddress" or can it be something like "karthik2.cs.sap.com"

THANKS...can i meet you online if you have msn/yahoo...

waiting for your reply.

Regards,
Karthik.




 
Thanks!. Your example worked. I used the smtp server of hotmail. however i can send emails only to valid hotmail id's right?. i cant specify any other id's apart from hotmail?

Thanks anyways. it worked. smtp.hotmail.com

Regards,
Karthik.
 
About James: Is it J2EE compatible library or its uses its own interface? I mean, can I just move J2EE web-application from one Server ( EE compatible ) to Tomcat with JAMES without changing code where application uses JavaMail?
 
Windows servers have SMTP as part of IIS. You would then put in "localhost" instead of hotmail's server. You would need to take the usual precautions against unauthorized relaying, of course.
 
lgarner :
How would that apply to using JavaMail within code running under Tomcat ?

alebu :
As far as I know, James is a MTA (Mail Transfer Agent), which is different to the common uses of JavaMail - which are usually as a MUA (Mail User Agent). Whatever, as long as you have the appropriate .jar files for either, you should be able to move them to Tomcat with no problems.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top