?? senduseauthenticator.java
字號:
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendUseAuthenticator{
public static void main(String[] args){
try{
//設置屬性值
Properties props = System.getProperties();
props.put("mail.smtp.host", "onecompany.com");
props.put("mail.smtp.auth", "true");
//Authenticator子類實例化
Authenticator auth = new ConsoleAuthenticator();
//獲得Session
Session session = Session.getDefaultInstance(props,auth);
//session.setDebug(true);
//寫郵件消息
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("xiaozhang@onecompany.com"));
Address toAddress=new InternetAddress("xiaoli@onecompany.com");
msg.addRecipient(Message.RecipientType.TO,toAddress);
msg.setSubject("JavaMail API TestMail ");
msg.setSentDate(new Date());
msg.setText("This is a test mail.");
//設置Transport發送消息
Transport.send(msg);
System.out.println("\n郵件已發送!");
}catch(Exception e){}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -