import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import com.test.sendToUser; import com.test.sendToUser.*; public class sendMail1 { public static void main(String[] ags)throws Exception { String host = "smtp.sina.com"; // 发件人使用发邮件的电子信箱服务器 String from = "[email protected]"; //"图档管理系统"; 发邮件的出发地(发件人的信箱) String to = "[email protected]"; // 发邮件的目的地(收件人信箱) // Get system properties Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", host); // Get session props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "photomanage", "********"); } }); session.setDebug(true); // Define message MimeMessage message = new MimeMessage(session); // Set the from address //message.setFrom(new InternetAddress(MimeUtility.encodeText(from))); message.setFrom(new InternetAddress(from)); // Set the to address message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set the subject message.setSubject("找回密码"); // Set the content // message.setText("欢迎你!"); message.saveChanges(); Transport.send(message); } }
import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; import com.test.sendToUser; import com.test.sendToUser.*; public class sendMail1 { public static void main(String[] ags)throws Exception { String host = "smtp.sina.com"; // 发件人使用发邮件的电子信箱服务器 String from = "[email protected]"; //"图档管理系统"; 发邮件的出发地(发件人的信箱) String to = "[email protected]"; // 发邮件的目的地(收件人信箱) // Get system properties Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", host); // Get session props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "photomanage", "********"); } }); session.setDebug(true); // Define message MimeMessage message = new MimeMessage(session); // Set the from address //message.setFrom(new InternetAddress(MimeUtility.encodeText(from))); message.setFrom(new InternetAddress(from)); // Set the to address message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set the subject message.setSubject("找回密码"); // Set the content // message.setText("欢迎你!"); message.saveChanges(); Transport.send(message); } }