import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
/**
* <p>Title: java mail</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author hekanhui
* @version 1.0
*/
public class sendMail
{
public sendMail()
{
}
public void send(){
try
{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
props.put("mail.smtp.host", "192.168.1.29"); //smtp主机名。
sendMailSession = Session.getInstance(props);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(""));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("")); //接收方邮件地址
newMessage.setSubject("java测试发送邮件");
newMessage.setSentDate(new Date());
String mailContent;
mailContent="成功没";
mailContent+="/n/n";
mailContent+=new Date().toLocaleString();
newMessage.setText(mailContent); //邮件正文
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
}
catch (MessagingException ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args)
{
sendMail sml = new sendMail();
System.out.println("发送开始!");
sml.send();
System.out.println("发送成功!");
}
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 PasswordAuthentication(username, password);
}
}
}