JSP發(fā)送郵件實(shí)例
更新時(shí)間:2006年10月13日 00:00:00 作者:
vishal_donth gave this response on 10/18/2000:
//these are the pakages to be imported from
// Java Mail
//The Java Mail PAckage either be dowloaded
//seperately
//or else is Available in the J2sdkee1.2
// (Java Enterprise Edition)
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
//This function can be used to send the mail
// with the parameters given to it
//U have to specify the smtp server through
//which u have to send the mail
//since i was trying with a homenetmail
//account i directly sent the mail its server
//For sending this mail u need a mail server
//which lets u to relay the messages
//Try this thing for sending to a
//www.homenetmail.com account because it lets
//u send
//mails to the accounts like example try
//sending it to a "abc@homenetmail.com"
//account.Create the mail account in homenet
//mail first. If u get any other server which
//supports relaying u can try this on that
//also.
//Use this function in ur Servlet to send
//mail by calling the function with the
//parameters
public void sendMail(String toAddr, String subject, String body, String fromAddr)throws RemoteException{
try{
Properties props = new Properties();
props.put("mail.smtp.host","mail.homenetmail.com");
//Here we specify the SMTP server through
//which the mail should be delivered
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddr));
//Specify the From Address
InternetAddress[] tos =InternetAddress.parse(toAddr);
//Specify the To Address
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
//Specify the Subject
msg.setText(body);
//Specify the Body
Transport.send(msg);
System.out.println("Message is Sent");
}
catch(Exception e){
System.out.println(e);
}
}
// U have to run this function on a computer
//which is directly connected
// to internet but not through a
//proxy......or else use a proxy which
//supports SMTP
//these are the pakages to be imported from
// Java Mail
//The Java Mail PAckage either be dowloaded
//seperately
//or else is Available in the J2sdkee1.2
// (Java Enterprise Edition)
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
//This function can be used to send the mail
// with the parameters given to it
//U have to specify the smtp server through
//which u have to send the mail
//since i was trying with a homenetmail
//account i directly sent the mail its server
//For sending this mail u need a mail server
//which lets u to relay the messages
//Try this thing for sending to a
//www.homenetmail.com account because it lets
//u send
//mails to the accounts like example try
//sending it to a "abc@homenetmail.com"
//account.Create the mail account in homenet
//mail first. If u get any other server which
//supports relaying u can try this on that
//also.
//Use this function in ur Servlet to send
//mail by calling the function with the
//parameters
public void sendMail(String toAddr, String subject, String body, String fromAddr)throws RemoteException{
try{
Properties props = new Properties();
props.put("mail.smtp.host","mail.homenetmail.com");
//Here we specify the SMTP server through
//which the mail should be delivered
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddr));
//Specify the From Address
InternetAddress[] tos =InternetAddress.parse(toAddr);
//Specify the To Address
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
//Specify the Subject
msg.setText(body);
//Specify the Body
Transport.send(msg);
System.out.println("Message is Sent");
}
catch(Exception e){
System.out.println(e);
}
}
// U have to run this function on a computer
//which is directly connected
// to internet but not through a
//proxy......or else use a proxy which
//supports SMTP
相關(guān)文章
Servlet+Jsp實(shí)現(xiàn)圖片或文件的上傳功能具體思路及代碼
web項(xiàng)目中的這一上傳功能,那么文件是如何從本地發(fā)送到服務(wù)器的呢,接下來為大家介紹下Servlet+Jsp實(shí)現(xiàn)文件的上傳功能,感興趣的朋友可以參考下哈2013-04-04運(yùn)用El表達(dá)式截取字符串/獲取list的長度實(shí)例
下面小編就為大家?guī)硪黄\(yùn)用El表達(dá)式截取字符串/獲取list的長度實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Jquery、Ajax、Struts2完成定時(shí)刷新的方法
今天一個(gè)需求,需要在頁面上動(dòng)態(tài)顯示后臺程序執(zhí)行的進(jìn)度,那么在頁面上會定時(shí)刷新,使用了Jquery、Ajax、Struts2。直接上代碼:2013-05-05動(dòng)態(tài)JSP頁生成靜態(tài)HTML的方法
這篇文章主要介紹了動(dòng)態(tài)JSP頁生成靜態(tài)HTML的方法,以實(shí)例形式較為詳細(xì)的分析了JSP生成靜態(tài)HTML頁面的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09JSP開發(fā)中Apache-HTTPClient 用戶驗(yàn)證的實(shí)例詳解
這篇文章主要介紹了JSP開發(fā)中Apache-HTTPClient 用戶驗(yàn)證的實(shí)例詳解的相關(guān)資料,這里提供實(shí)例幫助大家學(xué)習(xí)理解這部分內(nèi)容,需要的朋友可以參考下2017-08-08Spring 整合 Hibernate 時(shí)啟用二級緩存實(shí)例詳解
這篇文章主要介紹了Spring 整合 Hibernate 時(shí)啟用二級緩存實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-02-02