程式最火紅的一個範例了~~~
HELLO WORD!!
/* Java Mail 簡易版 */ import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class JavaMail { public static void main(String[] args) { try{ // 設定傳送基本資訊 String host = "Your host"; String from = "From mail Address"; String to = "To mail Address"; Properties props = System.getProperties(); //設定SMTP server props.put("mail.smtp.host",host); //依據Properties建立一個Session Session mailSession = Session.getInstance(props,null); //從Session建立一個Message Message mailMessage = new MimeMessage(mailSession); //Set from email address mailMessage.setFrom(new InternetAddress(from)); //Set to mail address mailMessage.setRecipient(Message.RecipientType.TO,new InternetAddress(to)); //設定標題 mailMessage.setSubject("Hello JavaMail"); //設定Mail內容 mailMessage.setText("Wellcome to JavaMail...加油!!"); //傳送 Transport.send(mailMessage); System.out.println("\n Mail was sent successfully."); }catch (Exception e){ System.out.println(e.getMessage()); } } }
全站熱搜
留言列表