javamail 發(fā)送驗證郵件(jspservlet實例源碼)_第1頁
javamail 發(fā)送驗證郵件(jspservlet實例源碼)_第2頁
javamail 發(fā)送驗證郵件(jspservlet實例源碼)_第3頁
javamail 發(fā)送驗證郵件(jspservlet實例源碼)_第4頁
javamail 發(fā)送驗證郵件(jspservlet實例源碼)_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、javamail 發(fā)送驗證郵件(jsp/servlet實例源碼) 發(fā)送email:包括文本郵件、html郵件、帶附件的郵件、smtp驗證  接收email:pop3遠(yuǎn)程連接、收取不同mime的郵件、處理附件  - 例子一、javamail.jsp 發(fā)送驗證郵件源代碼  boolean sessiondebug = false  authenticator auth = new authenticator() 

2、; /session mailsession = session.getdefaultinstance(props  auth)  /有時可能被拒絕 session mailsession = session.getinstance(props auth)  /用戶驗證  /session mailsession = session.getinstance(props)  ma

3、ilsession.setdebug(sessiondebug)  string text = " javamail.jsp 發(fā)送認(rèn)證郵件< b> 測試< /b> 。< hr> "  + contents  msg.setcontent(text  contenttype)  transport transpor

4、t = mailsession.gettransport(" smtp" )  transport.connect(host user password)  transport.send( msg )  > < p> 你的郵件已發(fā)送,< a href=" javascript:window.go(-1)" > 

5、;請返回。< /> < /p> <   catch(exception m)out.println(m.tostring() >  < /body>  < /html>   - 例子二、用servlet來發(fā)送郵件 ,postmail.java 源代碼   public void 

6、setaccount(string user string password)         this.user=user      this.password=password         (mimemessage)message).setsubject(subject  " gb

7、k" )    /得到中文標(biāo)題for linux,windows下不用         / message.setsubject(subject) /郵件主題          /內(nèi)容類型content-type   /普通文本為text/plain html格式為text/ht

8、ml     message.setcontent(content " text/html charset=gbk" )       /message.settext(" < html> < body> < h1> java mail,你好!< /body> &

9、lt; /html> " )            message.settext(content) /郵件內(nèi)容      message.savechanges()             transport transp

10、ort = mailsession.gettransport(" smtp" )       transport.connect(host  user  password)       transport.sendmessage(message  message.getallrecipients()   &#

11、160; public static void main(string args)       /  postmail sm=new postmail()      /        param string 發(fā)件人的地址     

12、;   param string 收件人地址        param string 郵件標(biāo)題        param string 郵件正文     /           調(diào)用post

13、mail.java的jsp文件:postmail.jsp源代碼  - 其他java源代碼:mailmanager.java 源代碼 package mail   -  sendmailusingauthentication.java 源代碼,引用這個java bean發(fā)送認(rèn)證email例子 package mail  import java.util.  /   to

14、 use this program  change values for the following three constants      smtp_host_name - has your smtp host name     smtp_auth_user - has your

15、60;smtp authentication username     smtp_auth_pwd  - has your smtp authentication password   next change values for fields   emailmsgtxt  - message text fo

16、r the email   emailsubjecttxt  - subject for email   emailfromaddress - email address whose name will appears as " from"  address   next change&#

17、160;value for " emaillist" .   this string array has list of all email addresses to email email needs to be sent to.    next to run the 

18、;program   ute it as follows    sendmailusingauthentication authprog = new sendmailusingauthentication()  / public class sendmailusingauthentication    private static final

19、60;string emailmsgtxt      = " online order confirmation message. also include the tracking number.中國人"     private static final string emailsubjecttxt 

20、60;= " 這里是標(biāo)題 java mail test"     private static final string emailfromaddress = " user "     / add list of email address to who

21、60;email needs to be sent to   private static final string emaillist = " username "   " xxxx "     public void postmail( string re

22、cipients  string subject    /public void postmail( string recipients  string subject                        &#

23、160;     string message   string from) throws messagingexception        boolean debug = false      authenticator auth = new smtpauthent

24、icator()      /session session = session.getdefaultinstance(props  auth)  /有時可能被拒絕    session session = session.getinstance(props auth)           session.setdebug(debug)      / create a message     message msg =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論