You must download Sun's JavaMail API package, address is: http://java.sun.com/products/javamail/ and add the associated package (JAR file) to ClassPath. Or if you install J2EE, add J2EE.jar to ClassPath.
The source program is as follows, replacing the red portion.
For you or have a problem, please contact: petehero@126.com
Import java.util. *; import javax.mail. *; import javax.mail.internet. *;
/ ** *
Title: Java Mail p> *
description: p> *
Copyright: Copyright (c) 2004 p> *
company: p> * @Author petehero * @version 1.0 * /
Public class sendmail {
Public sendmail () {} public void send () {try {prints = new profment (); session sendmailsession; store store; transport transport; prOPs.PUT ("mail.smtp.auth", "true"); Props. PUT ("mail.smtp.host", "smtp.yourmail.com"); // SMTP hostname. Props.Put ("mail.smtp.user", "username@yourmail.com"); // senders email address. Props.Put ("mail.smtp.password", "888888"); // mail password. Popupauthenticator popa = new popupauthenticator (); // message security authentication. PasswordAuthentication pop = popA.performCheck ( "username", "888888"); // fill in your username and password sendMailSession = Session.getInstance (props, popA); Message newMessage = new MimeMessage (sendMailSession); newMessage.setFrom (new InternetAddress ( "Username@yourmail.com"); newMessage.SetRecipient (Message.RecipientType.to, New InternetDress); // Receiver Email Address NEWMESSAGE.SETSUBJECT ("Mail Topic); newMessage .setSentDate (new date ()); string mailcontent; mailcontent = "Hello! / n / n"; mailcontent = "/ t mail body / n / n"; mailcontent = new date (). Tolocalestring (); newmedage. setText (mailContent); // message body transport = sendMailSession.getTransport ( "smtp"); transport.send (newMessage);} catch (MessagingException ex) {ex.printStackTrace ();}} public static void main (String [] Args) {sendmail sml = new sendmail (); SML.send ();
public class PopupAuthenticator extends Authenticator {String username = null; String password = null; public PopupAuthenticator () {} public PasswordAuthentication performCheck (String user, String pass) {username = user; password = pass; return getPasswordAuthentication ();} protected PasswordAuthentication getPasswordAuthentication () {Return New PasswordAutAuthentication (username, password);}}}