471,306 Members | 857 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

send mails via jsp/servlets

does any one have a clue as to how to send a mail via jsp/servlets.
Jul 17 '05 #1
3 6509

"mihir" <mi*****@indiatimes.com> wrote in message
news:3a**************************@posting.google.c om...
does any one have a clue as to how to send a mail via jsp/servlets.

Oui... http://java.sun.com/products/javamail/

Download the mail api and here's a little code example of how to do it....

<%
Session session2 = Session.getDefaultInstance(new
java.util.Properties(), null);
Transport transport = session2.getTransport("smtp");
transport.connect /* to a mailserver that can send the mail */
(
mailserver
, "username"
, "password"
);

MimeMessage email = new MimeMessage(session2);
email.setSubject("test");
email.setFrom(new InternetAddress("yo**@address.com", "This is me"));
email.setRecipient
(
Message.RecipientType.TO
, new InternetAddress("tohim/he*@redwood.com", "Your friend")
);

MimeBodyPart body = new MimeBodyPart();
String message = " bla bla bla "; /* The message */

email.setContent(message, "text/plain");

// Commented out for testing
transport.send(email, email.getAllRecipients());
%>

To be honoust... I just typed this in. There might be some mistakes. You can
either use Transport.send (which uses for example default mail on unix) or
connect to a server (which I do in the example) and the use the transport
object to send the mail instread of the static call.

Adieu,

Rein

Jul 17 '05 #2

"mihir" <mi*****@indiatimes.com> wrote in message
news:3a**************************@posting.google.c om...
does any one have a clue as to how to send a mail via jsp/servlets.

Oui... http://java.sun.com/products/javamail/

Download the mail api and here's a little code example of how to do it....

<%
Session session2 = Session.getDefaultInstance(new
java.util.Properties(), null);
Transport transport = session2.getTransport("smtp");
transport.connect /* to a mailserver that can send the mail */
(
mailserver
, "username"
, "password"
);

MimeMessage email = new MimeMessage(session2);
email.setSubject("test");
email.setFrom(new InternetAddress("yo**@address.com", "This is me"));
email.setRecipient
(
Message.RecipientType.TO
, new InternetAddress("tohim/he*@redwood.com", "Your friend")
);

MimeBodyPart body = new MimeBodyPart();
String message = " bla bla bla "; /* The message */

email.setContent(message, "text/plain");

// Commented out for testing
transport.send(email, email.getAllRecipients());
%>

To be honoust... I just typed this in. There might be some mistakes. You can
either use Transport.send (which uses for example default mail on unix) or
connect to a server (which I do in the example) and the use the transport
object to send the mail instread of the static call.

Adieu,

Rein

Jul 17 '05 #3
Here is some example code :

http://www.javapractices.com/Topic144.cjp

mihir wrote:
does any one have a clue as to how to send a mail via jsp/servlets.


Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by muskan | last post: by
7 posts views Thread by oopsbabies | last post: by
reply views Thread by rosydwin | last post: by

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.