[筆記] 傳智播客-javaWeb筆記(4)
阿新 • • 發佈:2019-02-12
";
String username = "chengyuqing110";
String password = "12345678";
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO,to);
message.setSubject("這是試驗");
//===設定附件的正文=======================================
MimeBodyPart bp1=new MimeBodyPart();
bp1.setText("正文");
//===============設定附件==================================
MimeBodyPart bp2=new MimeBodyPart();
bp2.setDataHandler(new DataHandler(new FileDataSource("c:\\過濾器.ppt")));
bp2.setFileName(MimeUtility.encodeText("c:\\過濾器.ppt")); //處理中文
//================================加入附件裡面=======================
Multipart mp=new MimeMultipart();
mp.addBodyPart(bp1);
mp.addBodyPart(bp2);
message.setContent(mp);
//==================================================================
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
//====================================================================
收郵件
String Uid =request.getParameter("txtUid");//郵件伺服器的使用者名稱
String Pwd =request.getParameter("txtPwd");//郵件伺服器的密碼
String Host =request.getParameter("txtHost");//郵件伺服器的主機名,一般是pop.sina.com或pop.163.com
Properties props = new Properties();
Session Getsession=Session.getDefaultInstance(props);//建立session
Store store = Getsession.getStore("pop3");
store.connect(Host,Uid,Pwd);
Folder folder=store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] message=folder.getMessages();
String username = "chengyuqing110";
String password = "12345678";
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO,to);
message.setSubject("這是試驗");
//===設定附件的正文=======================================
MimeBodyPart bp1=new MimeBodyPart();
bp1.setText("正文");
//===============設定附件==================================
MimeBodyPart bp2=new MimeBodyPart();
bp2.setDataHandler(new DataHandler(new FileDataSource("c:\\過濾器.ppt")));
bp2.setFileName(MimeUtility.encodeText("c:\\過濾器.ppt")); //處理中文
//================================加入附件裡面=======================
Multipart mp=new MimeMultipart();
mp.addBodyPart(bp1);
mp.addBodyPart(bp2);
message.setContent(mp);
//==================================================================
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
//====================================================================
收郵件
String Uid =request.getParameter("txtUid");//郵件伺服器的使用者名稱
String Pwd =request.getParameter("txtPwd");//郵件伺服器的密碼
String Host =request.getParameter("txtHost");//郵件伺服器的主機名,一般是pop.sina.com或pop.163.com
Properties props = new Properties();
Session Getsession=Session.getDefaultInstance(props);//建立session
Store store = Getsession.getStore("pop3");
store.connect(Host,Uid,Pwd);
Folder folder=store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] message=folder.getMessages();