当前位置: 技术问答>java相关
谁有JAVAMAIL的例子?给我一个
来源: 互联网 发布时间:2015-07-05
本文导语: 谁有JAVAMAIL的例子?给我一个 | 我可以介绍一个给你,这是我用Servlet编的一个javamail,希望对你有用: import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import javax.mail.*; im...
谁有JAVAMAIL的例子?给我一个
|
我可以介绍一个给你,这是我用Servlet编的一个javamail,希望对你有用:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class ExaServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
try{
Properties props = System.getProperties();
Session sendMailSession;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.bhr.com.cn");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("xxx@xxx.com.cn"));
newMessage.setSentDate(new Date());
newMessage.setSubject();
String text = "";
newMessage.setText(text);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
}
catch(MessagingException m)
{
//out.println(m.toString());
}
}
}
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class ExaServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
try{
Properties props = System.getProperties();
Session sendMailSession;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.bhr.com.cn");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("xxx@xxx.com.cn"));
newMessage.setSentDate(new Date());
newMessage.setSubject();
String text = "";
newMessage.setText(text);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
}
catch(MessagingException m)
{
//out.println(m.toString());
}
}
}
|
sun 有也