当前位置: 技术问答>java相关
如何使用jsp发送邮件
来源: 互联网 发布时间:2015-04-04
本文导语: 如何使用jsp发送邮件 | import javax.mail.*; import javax.mail.internet.*; import java.util.*; public void sendMail(String toAddr, String subject, String body, String fromAddr)throws RemoteException{ try{ Properties props...
如何使用jsp发送邮件
|
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
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");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddr));
InternetAddress[] tos =InternetAddress.parse(toAddr);
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
msg.setText(body);
Transport.send(msg);
System.out.println("Message is Sent");
}
catch(Exception e){
System.out.println(e);
}
}
import javax.mail.internet.*;
import java.util.*;
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");
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddr));
InternetAddress[] tos =InternetAddress.parse(toAddr);
msg.setRecipients(Message.RecipientType.TO,tos);
msg.setSubject(subject);
msg.setText(body);
Transport.send(msg);
System.out.println("Message is Sent");
}
catch(Exception e){
System.out.println(e);
}
}