473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

send mail using java

Hi to all I am a new member to this group. I have a problem in Email Sending using java. That is the mail is sending from my server to any desired mail account. By using the html i created the form but i am not able to send the mail .please any one give the solution to do my project effectively. I submit the html code for example form.

code:

<html>
<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Using this form i want to send the mail through server.Please send your suggestion to me.

Thankyou very much,
Regards
Geetha.
Jan 4 '07 #1
12 8646
r035198x
13,262 8TB
Hi to all I am a new member to this group. I have a problem in Email Sending using java. That is the mail is sending from my server to any desired mail account. By using the html i created the form but i am not able to send the mail .please any one give the solution to do my project effectively. I submit the html code for example form.

code:

<html>
<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Using this form i want to send the mail through server.Please send your suggestion to me.

Thankyou very much,
Regards
Geetha.
This may or may not have anything to do with java. To send mail using java one should have a look at the java mail api. I doubt that this is what you want to do.

Have a look at the mailto command and tell us if that's not what you want.
Jan 4 '07 #2
This may or may not have anything to do with java. To send mail using java one should have a look at the java mail api. I doubt that this is what you want to do.

Have a look at the mailto command and tell us if that's not what you want.
Thank you for your reply. the html code i send is only for reference for that format i want to send a mail using java servlets or also using the jsp .that is the email is send to our customers through my server (Tomcat web server).
Jan 4 '07 #3
r035198x
13,262 8TB
Thank you for your reply. the html code i send is only for reference for that format i want to send a mail using java servlets or also using the jsp .that is the email is send to our customers through my server (Tomcat web server).
Ah, well then if you are using j2ee then
http://www.javapractices.com/Topic144.cjp is probably what you need.
Jan 4 '07 #4
abctech
157 100+
Hi to all I am a new member to this group. I have a problem in Email Sending using java. That is the mail is sending from my server to any desired mail account. By using the html i created the form but i am not able to send the mail .please any one give the solution to do my project effectively. I submit the html code for example form.

code:

<html>
<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Using this form i want to send the mail through server.Please send your suggestion to me.

Thankyou very much,
Regards
Geetha.
Hi to all I am a new member to this group. I have a problem in Email Sending using java. That is the mail is sending from my server to any desired mail account. By using the html i created the form but i am not able to send the mail .please any one give the solution to do my project effectively. I submit the html code for example form.

code:

<html>
<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Using this form i want to send the mail through server.Please send your suggestion to me.

Thankyou very much,
Regards
Geetha.
-------------------------------------------------------------------------------------------------------------------
Hi,
If u are using a Servlet for processing then u need to add the <action> tag in ur Html page above the <body> tag..This is how ur Html page should look like :-

<html>

<form method="POST" action="http://localhost:8000/Geethu/SM">

<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Now depending on wt Http-method(Get,Post,Head etc.. ) u want to use..the most common being "Get" and "Post"..u mention it in the method-attribute of <form> ..
Here we are using Post and note tht even in the corresponding HttpServlet class u hv to use "doPost()" ..

In the action attribute of the <form> I have given the URL for the HttpServlet which needs to be invoked after hitting the 'Submit' button,
If u r working with J2EE then u must be familiar with the terms URL and that it comprises of : 'protocol','machine name and number','port number','resources' ,

I have deployed this prg in J2ee server where we have a 'context-root' and 'alias' during deployment to identify the web-application & resource respectively
(in this particular program the resource happens to be the servlet :- SendMailServlet identified by alias -"SM" and I've assumed the context root to be "Geethu") ,

Now wt we are doing is we are collecting the info frm the Html Page and passing it to our Servlet which we hv named: SendMailServlet.java and this Servlet in turn will handle the EMail-send operation.

The Servlet program:-

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

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

public class SendMailServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String body = request.getParameter("body");

sendEmail(to,from,subject,body) ; //call to the sendEmail() method
}

protected void sendEmail(String a,String b,String c,String d)
{
String toSomeone = a;
String fromMe = b;
String subj = c;
String content = d;

try
{
//Set up the default parameters

Properties props = new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host","--*N-O-T-E*----"); // *Note*:- here u need to write the name of ur smtp_server
props.put("mail.smtp.port","25");

//Create the session and create a new mail message
Session session = Session.getInstance(props);
Message msg = new MimeMessage(session);

//Set the From,To,Date and Subject fields
msg.setFrom(new InternetAddress(fromMe)); //from
msg.setRecipients(Message.RecipientType.TO,Interne tAddress.parse(toSomeone)); //to
msg.setSentDate(new java.util.Date());
msg.setSubject(subj); //subject of ur mail
msg.setText(content); //body of ur mail

Transport.send(msg);

msg.writeTo(System.out);

}
catch(Exception e)
{
System.out.println(e);
}

}//sendEmail() over

}//SendMailServlet over

First specify the name of ur smtp_Server in the above servlet at the marked posn, compile the sevlet prg, add it to ur web-application, deploy, and chek the o/p

To get a better idea of the classes and methods etc used here u cn refer to the chapter "JavaMail" from the book "Professional Java Server Programming"

Hope this helps......
Jan 6 '07 #5
-------------------------------------------------------------------------------------------------------------------
Hi,
If u are using a Servlet for processing then u need to add the <action> tag in ur Html page above the <body> tag..This is how ur Html page should look like :-

<html>

<form method="POST" action="http://localhost:8000/Geethu/SM">

<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Now depending on wt Http-method(Get,Post,Head etc.. ) u want to use..the most common being "Get" and "Post"..u mention it in the method-attribute of <form> ..
Here we are using Post and note tht even in the corresponding HttpServlet class u hv to use "doPost()" ..

In the action attribute of the <form> I have given the URL for the HttpServlet which needs to be invoked after hitting the 'Submit' button,
If u r working with J2EE then u must be familiar with the terms URL and that it comprises of : 'protocol','machine name and number','port number','resources' ,

I have deployed this prg in J2ee server where we have a 'context-root' and 'alias' during deployment to identify the web-application & resource respectively
(in this particular program the resource happens to be the servlet :- SendMailServlet identified by alias -"SM" and I've assumed the context root to be "Geethu") ,

Now wt we are doing is we are collecting the info frm the Html Page and passing it to our Servlet which we hv named: SendMailServlet.java and this Servlet in turn will handle the EMail-send operation.

The Servlet program:-

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

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

public class SendMailServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String body = request.getParameter("body");

sendEmail(to,from,subject,body) ; //call to the sendEmail() method
}

protected void sendEmail(String a,String b,String c,String d)
{
String toSomeone = a;
String fromMe = b;
String subj = c;
String content = d;

try
{
//Set up the default parameters

Properties props = new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host","--*N-O-T-E*----"); // *Note*:- here u need to write the name of ur smtp_server
props.put("mail.smtp.port","25");

//Create the session and create a new mail message
Session session = Session.getInstance(props);
Message msg = new MimeMessage(session);

//Set the From,To,Date and Subject fields
msg.setFrom(new InternetAddress(fromMe)); //from
msg.setRecipients(Message.RecipientType.TO,Interne tAddress.parse(toSomeone)); //to
msg.setSentDate(new java.util.Date());
msg.setSubject(subj); //subject of ur mail
msg.setText(content); //body of ur mail

Transport.send(msg);

msg.writeTo(System.out);

}
catch(Exception e)
{
System.out.println(e);
}

}//sendEmail() over

}//SendMailServlet over

First specify the name of ur smtp_Server in the above servlet at the marked posn, compile the sevlet prg, add it to ur web-application, deploy, and chek the o/p

To get a better idea of the classes and methods etc used here u cn refer to the chapter "JavaMail" from the book "Professional Java Server Programming"

Hope this helps......

Hi
Thank you for your code. i done as you tell but at the time of complie i have some error pls tell what is the problem. any jar files are added for this program.
I already have the mail and activation jar files in my lib directory. I am in confusion please help me.

The Errors are
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapp
ses>javac SendMailServlet.java
SendMailServlet.java:5: package javax.mail does not exist
import javax.mail.*;
^
SendMailServlet.java:6: package javax.activation does not exi
import javax.activation.*;
^
SendMailServlet.java:7: package javax.mail.internet does not
import javax.mail.internet.*;
^
SendMailServlet.java:39: cannot find symbol
symbol : class Session
location: class SendMailServlet
Session session = Session.getInstance(props);
^
SendMailServlet.java:39: cannot find symbol
symbol : variable Session
location: class SendMailServlet
Session session = Session.getInstance(props);
^
SendMailServlet.java:40: cannot find symbol
symbol : class Message
location: class SendMailServlet
Message msg = new MimeMessage(session);
^
SendMailServlet.java:40: cannot find symbol
symbol : class MimeMessage
location: class SendMailServlet
Message msg = new MimeMessage(session);
^
SendMailServlet.java:43: cannot find symbol
symbol : class InternetAddress
location: class SendMailServlet
msg.setFrom(new InternetAddress(fromMe)); //from

Thanks
Jan 9 '07 #6
abctech
157 100+
Hi
Thank you for your code. i done as you tell but at the time of complie i have some error pls tell what is the problem. any jar files are added for this program.
I already have the mail and activation jar files in my lib directory. I am in confusion please help me.

The Errors are
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapp
ses>javac SendMailServlet.java
SendMailServlet.java:5: package javax.mail does not exist
import javax.mail.*;
^
SendMailServlet.java:6: package javax.activation does not exi
import javax.activation.*;
^
SendMailServlet.java:7: package javax.mail.internet does not
import javax.mail.internet.*;
^
SendMailServlet.java:39: cannot find symbol
symbol : class Session
location: class SendMailServlet
Session session = Session.getInstance(props);
^
SendMailServlet.java:39: cannot find symbol
symbol : variable Session
location: class SendMailServlet
Session session = Session.getInstance(props);
^
SendMailServlet.java:40: cannot find symbol
symbol : class Message
location: class SendMailServlet
Message msg = new MimeMessage(session);
^
SendMailServlet.java:40: cannot find symbol
symbol : class MimeMessage
location: class SendMailServlet
Message msg = new MimeMessage(session);
^
SendMailServlet.java:43: cannot find symbol
symbol : class InternetAddress
location: class SendMailServlet
msg.setFrom(new InternetAddress(fromMe)); //from

Thanks
Hi,

Have you set the classpath? i.e the path of the jar file of the server that you are using?
For eg:-
I am using J2EE server so my classpath is like this:-
.;C:\j2sdkee1.3.1\lib\j2ee.jar

If you were using Weblogic then it would be :-
.;C:\j2sdkee1.3.1\lib\weblogic.jar


so accordingly whichever server you are using do keep the jar file for the same in the classpath , the jar file contains the entire API so without keeping it in the classpath you wont be able to compile successfully, please check ..
Jan 9 '07 #7
abctech
157 100+
Hi again,

I think by mistake I might have specified the classpath for Weblogic incorrectly, but anyways I think you are using Tomcat so you might find the foll link useful

http://www.coreservlets.com/Apache-Tomcat-Tutorial/#Set-CLASSPATH

Please do check ...
Jan 9 '07 #8
Hi to all I am a new member to this group. I have a problem in Email Sending using java. That is the mail is sending from my server to any desired mail account. By using the html i created the form but i am not able to send the mail .please any one give the solution to do my project effectively. I submit the html code for example form.

code:

<html>
<body>

<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>To:</td>
<td>
<input type="text" name="to" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>From:</td>
<td>
<input type="text" name="from" size="30" maxlength="30">
</td>
</tr>
<tr>
<td>Subject</td>
<td>
<input type="text" name="subject" size="30" maxlength="30">
</td>
</tr>
<tr>
<td colspan="2">
<textarea cols="40" rows="10" name="body"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
<input type="Reset">
</td>
</tr>
</table>
</body>
</html>

Using this form i want to send the mail through server.Please send your suggestion to me.

Thankyou very much,
Regards
Geetha.


Hi iam new to java mail can u pls send me the complete codings of sending mail.......My id <Removed: against site rules>
Mar 6 '07 #9
Hi iam new to java mail can u pls send me the complete codings of sending mail.......My id [deleted]
Hi Anand
Sendingmail using JAVA is very complex. So done it by using the PHP.Its very easy to compare the Java. If you want the Php code i will send it to you. Php code is same like html code.

Reply me if you want the code,

Regards,
Geethu.
Mar 6 '07 #10
r035198x
13,262 8TB
Hi Anand
Sendingmail using JAVA is very complex. So done it by using the PHP.Its very easy to compare the Java. If you want the Php code i will send it to you. Php code is same like html code.

Reply me if you want the code,

Regards,
Geethu.
No it's not complex. The java mail API is very easy to use if you know a bit of Java. I think the PHP is easier for PHP developers.
Mar 6 '07 #11
No it's not complex. The java mail API is very easy to use if you know a bit of Java. I think the PHP is easier for PHP developers.
yes I know little bit of Java. But i don't know about mail API. Please give the details about the mail API.

Thank you,
Geethu
Mar 6 '07 #12
Hai guys can any one of u guide me how to send mail to a mailing list using java
Feb 8 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mihir | last post by:
does any one have a clue as to how to send a mail via jsp/servlets.
0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
2
by: tomtailor | last post by:
Hello! I'm migrating from pgSQL and WinXP to DB2 8.2 on SuSE 9.2 and I'd like to send E-Mails by triggers. I found some code for Java stored Procedures but I'm not able to get JavaDK running in...
0
by: jlconde | last post by:
I have a classe to send mails. It runs on yahoo well but with hotmail I never receive the mails.I do not receive an error neither. I would need some strange header to make the hotmail like my...
3
by: crossroadsk | last post by:
<pre> Hi all, I'm new to Javamail concept and i got the following exceptions when i tried to send a simple mail. First exception is : using java Could not connect to SMTP host:...
0
by: sudipmondal440 | last post by:
import javax.mail.*; import javax.mail.internet.*; import java.util.*; import javax.activation.*; import javax.swing.text.*; import javax.swing.*; import java.io.*; import java.awt.*; ...
5
by: Sekkappan | last post by:
hi, I am new to javamail.now i urgently want a code to send a mail through java program.i am using struts application. can any one explain me clearly about procedure to send to using java...
2
by: btcoder | last post by:
Hi, my jsp page uses sun.net.smtp.SmtpClient to send email. It worked fine until the hosted location was moved to another server. Now it generates the sun.net.smtp.SmtpProtocolException and the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.