aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Sending Email from Servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Sending Email from Servlet." Watch "Sending Email from Servlet." New topic
Author

Sending Email from Servlet.

inhaer Mc
Greenhorn

Joined: Aug 31, 2005
Posts: 1
I am quite new with Servlet/JSP. How can i send an email from an servlet? Thank you for your help !
Jiang Xiaofeng
Greenhorn

Joined: Jul 19, 2005
Posts: 25
Originally posted by inhaer Mc:
I am quite new with Servlet/JSP. How can i send an email from an servlet? Thank you for your help !



Use JavaMail: http://java.sun.com/products/javamail/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

"inhaer Mc",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

Moved to the Other APis forum.
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Include pop3.jar, activation.jar, Jmail.jar, mail.jar, mailapi.jar files in the classpath.

Include part of the code snippet in ur servlet.

try
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
//props.put("mail.smtp.host", "smtp.jcom.net");
props.put("mail.smtp.host", smtphost);
props.put("mail.smtp.auth", "true");


// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
Session mailSession = Session.getDefaultInstance(props, null);

session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.addHeader("MyHeaderName", "myHeaderValue");
msg.setHeader("X-Mailer", "JavaMail API");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
msg.setSentDate(new Date());
Transport.send(msg,addressTo);
}
catch (MessagingException mex) {}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending Email from Servlet.