package com.xl.action;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TxEmail extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String content=new String(request.getParameter("content").getBytes("iso-8859-1"));
String tal=new String(request.getParameter("tal").getBytes("iso-8859-1"));
String tx_email =request.getParameter("email");//发送人EAMIL
String pass =new String(request.getParameter("pass").getBytes("iso-8859-1"));//EMAIL密码
String addres=new String(request.getParameter("addres").getBytes("iso-8859-1"));//住址
String tto=request.getParameter("tto");//收件人地址
try{
String type_email=tx_email.substring(tx_email.lastIndexOf("@")+1, tx_email.lastIndexOf("."));
System.out.println(tx_email+" "+pass+" 0.0.0.0.0..0.0..");
String ttitle="公司网站有留言,请注意查看!";
//String tcontent="<hr><br/><object classid=clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95 codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,5,217' id=MediaPlayer type=application/x-oleobject width=210 height=340 standby='Loading Microsoft Windows Media Player components...' VIEWASTEXT align=MIDDLE><param name=AudioStream value=-1><param name=AutoSize value=0><param name=AutoStart value=1> <param name=AnimationAtStart value=0><param name=AllowScan value=-1><param name=AllowChangeDisplaySize value=0><param name=AutoRewind value=0><param name=Balance value=0><param name=BaseURL value=''><param name=BufferingTime value=5><param name=CaptioningID value=''><param name=ClickToPlay value=0><param name=CursorType value=32512><param name=CurrentPosition value=-1><param name=CurrentMarker value=0><param name=DefaultFrame value=1><param name=DisplayBackColor value=0><param name=DisplayForeColor value=16777215><param name=DisplayMode value=0><param name=DisplaySize value=0><param name=Enabled value=-1><param name=EnableContextMenu value=-1><param name=EnablePositionControls value=0><param name=EnableFullScreenControls value=0><param name=EnableTracker value=1><param name=Filename value='http://down.twochong.com/20090102193927250.mp3'><param name=InvokeURLs value=-1><param name=Language value=-1><param name=Mute value=0><param name=PlayCount value=1><param name=PreviewMode value=0><param name=Rate value=1><param name=SAMILang value=''><param name=SAMIStyle value=''><param name=SAMIFileName value=''><param name=SelectionStart value=0><param name=SelectionEnd value=true>param name=SendOpenStateChangeEvents value=-1><param name=SendWarningEvents value=-1><param name=SendErrorEvents value=-1><param name=SendKeyboardEvents value=0><param name=SendMouseClickEvents value=0><param name=SendMouseMoveEvents value=0><param name=SendPlayStateChangeEvents value=-1><param name=ShowCaptioning value=0><param name=ShowControls value=1><param name=ShowAudioControls value=1><param name=ShowDisplay value=1><param name=ShowGotoBar value=1><param name=ShowPositionControls value=1><param name=ShowStatusBar value=1><param name=ShowTracker value=1><param name=TransparentAtStart value=0><param name=VideoBorderWidth value=0><param name=VideoBorderColor value=0><param name=VideoBorder3D value=0><param name=Volume value=-1070><param name=WindowlessVideo value=1></object><br/>aaaaa";
String tcontent="电话:"+tal+"<br>邮箱:"+tx_email+"<br>地址:"+addres+"<br>"+"留言内容:"+content;
Properties props=new Properties();
props.put("mail.smtp.host","smtp."+type_email+".com");
props.put("mail.smtp.auth","true");
Session s=Session.getInstance(props);
s.setDebug(true);
MimeMessage message=new MimeMessage(s);
// 给消息对象设置发件人/收件人/主题/发信时间
InternetAddress from=new InternetAddress(tx_email);
message.setFrom(from);
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject(ttitle);
message.setSentDate(new Date());
// 给消息对象设置内容
BodyPart mdp=new MimeBodyPart();//新建一个存放信件内容的BodyPart对象
mdp.setContent(tcontent,"text/html;charset=utf-8");//给BodyPart对象设置内容和格式/编码方式
Multipart mm=new MimeMultipart();//新建一个MimeMultipart对象用来存放BodyPart对
// 象(事实上可以存放多个)
mm.addBodyPart(mdp);//将BodyPart加入到MimeMultipart对象中(可以加入多个BodyPart)
message.setContent(mm);//把mm作为消息对象的内容521loveshitou. microsoft_hang@sina.com
message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect("smtp."+type_email+".com",tx_email,pass);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
System.out.println("发送成功!");
}catch (Exception e){
e.printStackTrace();
// TODO: handle exception
}
System.out.println("发送成功!!!!");
request.getRequestDispatcher("Main.jsp").forward(request, response);
}
}
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TxEmail extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String content=new String(request.getParameter("content").getBytes("iso-8859-1"));
String tal=new String(request.getParameter("tal").getBytes("iso-8859-1"));
String tx_email =request.getParameter("email");//发送人EAMIL
String pass =new String(request.getParameter("pass").getBytes("iso-8859-1"));//EMAIL密码
String addres=new String(request.getParameter("addres").getBytes("iso-8859-1"));//住址
String tto=request.getParameter("tto");//收件人地址
try{
String type_email=tx_email.substring(tx_email.lastIndexOf("@")+1, tx_email.lastIndexOf("."));
System.out.println(tx_email+" "+pass+" 0.0.0.0.0..0.0..");
String ttitle="公司网站有留言,请注意查看!";
//String tcontent="<hr><br/><object classid=clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95 codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,5,217' id=MediaPlayer type=application/x-oleobject width=210 height=340 standby='Loading Microsoft Windows Media Player components...' VIEWASTEXT align=MIDDLE><param name=AudioStream value=-1><param name=AutoSize value=0><param name=AutoStart value=1> <param name=AnimationAtStart value=0><param name=AllowScan value=-1><param name=AllowChangeDisplaySize value=0><param name=AutoRewind value=0><param name=Balance value=0><param name=BaseURL value=''><param name=BufferingTime value=5><param name=CaptioningID value=''><param name=ClickToPlay value=0><param name=CursorType value=32512><param name=CurrentPosition value=-1><param name=CurrentMarker value=0><param name=DefaultFrame value=1><param name=DisplayBackColor value=0><param name=DisplayForeColor value=16777215><param name=DisplayMode value=0><param name=DisplaySize value=0><param name=Enabled value=-1><param name=EnableContextMenu value=-1><param name=EnablePositionControls value=0><param name=EnableFullScreenControls value=0><param name=EnableTracker value=1><param name=Filename value='http://down.twochong.com/20090102193927250.mp3'><param name=InvokeURLs value=-1><param name=Language value=-1><param name=Mute value=0><param name=PlayCount value=1><param name=PreviewMode value=0><param name=Rate value=1><param name=SAMILang value=''><param name=SAMIStyle value=''><param name=SAMIFileName value=''><param name=SelectionStart value=0><param name=SelectionEnd value=true>param name=SendOpenStateChangeEvents value=-1><param name=SendWarningEvents value=-1><param name=SendErrorEvents value=-1><param name=SendKeyboardEvents value=0><param name=SendMouseClickEvents value=0><param name=SendMouseMoveEvents value=0><param name=SendPlayStateChangeEvents value=-1><param name=ShowCaptioning value=0><param name=ShowControls value=1><param name=ShowAudioControls value=1><param name=ShowDisplay value=1><param name=ShowGotoBar value=1><param name=ShowPositionControls value=1><param name=ShowStatusBar value=1><param name=ShowTracker value=1><param name=TransparentAtStart value=0><param name=VideoBorderWidth value=0><param name=VideoBorderColor value=0><param name=VideoBorder3D value=0><param name=Volume value=-1070><param name=WindowlessVideo value=1></object><br/>aaaaa";
String tcontent="电话:"+tal+"<br>邮箱:"+tx_email+"<br>地址:"+addres+"<br>"+"留言内容:"+content;
Properties props=new Properties();
props.put("mail.smtp.host","smtp."+type_email+".com");
props.put("mail.smtp.auth","true");
Session s=Session.getInstance(props);
s.setDebug(true);
MimeMessage message=new MimeMessage(s);
// 给消息对象设置发件人/收件人/主题/发信时间
InternetAddress from=new InternetAddress(tx_email);
message.setFrom(from);
InternetAddress to=new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO,to);
message.setSubject(ttitle);
message.setSentDate(new Date());
// 给消息对象设置内容
BodyPart mdp=new MimeBodyPart();//新建一个存放信件内容的BodyPart对象
mdp.setContent(tcontent,"text/html;charset=utf-8");//给BodyPart对象设置内容和格式/编码方式
Multipart mm=new MimeMultipart();//新建一个MimeMultipart对象用来存放BodyPart对
// 象(事实上可以存放多个)
mm.addBodyPart(mdp);//将BodyPart加入到MimeMultipart对象中(可以加入多个BodyPart)
message.setContent(mm);//把mm作为消息对象的内容521loveshitou. microsoft_hang@sina.com
message.saveChanges();
Transport transport=s.getTransport("smtp");
transport.connect("smtp."+type_email+".com",tx_email,pass);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
System.out.println("发送成功!");
}catch (Exception e){
e.printStackTrace();
// TODO: handle exception
}
System.out.println("发送成功!!!!");
request.getRequestDispatcher("Main.jsp").forward(request, response);
}
}