jsp 的程序:
<%@ page
import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"
%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
String from=request.getParameter("from");
String to=request.getParameter("to");String subject=new String(request.getParameter("subject").getBytes("ISO8859-1"),"GB2312");String text=new String(request.getParameter("neirong").getBytes("ISO8859-1"),"GB2312");try{
Properties props = System.getProperties();
Session sendMailSession;
Store store;
Transport transport;props.put("mail.smtp.host", "smtp.eyou.com");
sendMailSession = Session.getInstance(props, null);Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
newMessage.setSubject(subject);
newMessage.setText(text);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>
<%@ page
import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"
%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
String from=request.getParameter("from");
String to=request.getParameter("to");String subject=new String(request.getParameter("subject").getBytes("ISO8859-1"),"GB2312");String text=new String(request.getParameter("neirong").getBytes("ISO8859-1"),"GB2312");try{
Properties props = System.getProperties();
Session sendMailSession;
Store store;
Transport transport;props.put("mail.smtp.host", "smtp.eyou.com");
sendMailSession = Session.getInstance(props, null);Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
newMessage.setSubject(subject);
newMessage.setText(text);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>
解决方案 »
- 清除Work缓存后,重启tomcat,出现不能编译JSP文件的问题
- Java事务问题,请各位路过的兄弟帮忙,多谢!
- ?求助=商业jsp网站怎么使动态转变成了静态!
- 欢饮加入java北京技术群(108082811)
- 使用PreparedStatement插入字符的最大值是如何限制的
- 请问:我生成的类,直接放在WEB_INF下的CLASS文件夹中就可以了吗?
- 急,高手救命!getOutputStream() Exception (第二次发帖)
- 给JSP+JAVABEAN开发的WEB应用程序打包(也许我用词不当)都用什么软件?请具体说明,多谢
- html中有没有类似IE地址栏的东东? 能自己输入,又能在下拉里面找东东。
- 疑惑:servlet是什么用的是否只有dopost.doget.dedel.doput这几个方法啊?这几个方法有什么区别?在什么时候使用?在线给分.
- 谁用过mysql和tomcat开发jsp呀,说说怎么配置的?谢谢各位大侠了!
- 如何在系统启动时自动启动tomcat或risn等的应用服务
这里的问题吧,你应该使用参数来设置正确的smtp服务器的
public static void main(String[] args) {
String host = "smtp.pubinfo.com.cn";
String from = "[email protected]";
String to = "[email protected]";
String username = "****";
String password = "****";
String subject = "中文测试Send Mail Testing";
String content = "中文测试"; MailSend mailsend = new MailSend(host,from,to,username,password,subject,content);
mailsend.msgSend();
System.exit(0);
}/////////////////////////////////////////////////////////
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
import javax.activation.*;public class MailSend{
String host;
String from;
String to;
String username;
String password;
String subject;
String content; public MailSend(String host,String from,String to,String username,
String password,String subject,String content){
this.host = host;
this.from = host;
this.to = to;
this.username = username;
this.password = password;
this.subject = subject;
this.content = content;
} public void msgSend(){
try{
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
//Setup mail Auth
Authenticator auth = new MyAuthenticator(username,password);
// Get session
Session session = Session.getDefaultInstance(props, auth); // Define message
MimeMessage message = new MimeMessage(session); // Set the from address
message.setFrom(new InternetAddress(from)); // Set the to address
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
// Set the subject
message.setSubject(subject);
// Set the content
message.setText(content);
// Send message
Transport.send(message); System.out.println("\nMail was sent successfully.");
}catch(Exception theException) {
System.out.println(theException);
} }
}////////////////////////////////////////
import javax.mail.*;
import java.util.*;public class MyAuthenticator extends Authenticator {
String username, password; public MyAuthenticator(String username,String password)
{
this.username = username;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}}