1 public interface OrderManager extends BaseManager{ 2 /** 3 *email,要发送的邮件地址; 4 *Code:激活码 5 */ 6 public void placeOrder(String email); 7 } |
1 import javax.mail.Message; 2 import javax.mail.MessagingException; 3 import javax.mail.internet.InternetAddress; 4 import javax.mail.internet.MimeMessage; 5 import org.springframework.mail.MailException; 6 import org.springframework.mail.javamail.JavaMailSender; 7 import org.springframework.mail.javamail.MimeMessagePreparator; 8 import service.OrderManager; 9 11 public class OrderManagerImpl extends BaseManagerImpl implements OrderManager { 12 13 private JavaMailSender mailsender; 14 private MyMailMessage message; 15 16 17 public void setMessage(CityMailMessage message) 18 { 19 this.message = message; 20 } 21 public void setMailsender(JavaMailSender mailsender) { 22 this.mailsender = mailsender; 23 } 24 public void placeOrder(final String email) { 25 26 27 MimeMessagePreparator preparator = new MimeMessagePreparator() { 28 public void prepare(MimeMessage mimeMessage) throws MessagingException { 29 mimeMessage.setRecipient(Message.RecipientType.TO, 30 new InternetAddress(email)); 31 mimeMessage.setFrom(new InternetAddress(message.getFrom())); 32 /**转换编码为GBK*/ 33 mimeMessage.setSubject(message.getSubject(),"GBK"); 36 mimeMessage.setText(email+"<br>"+message.getSubject()+message.getText(),"GBK"); 37 38 } 39 }; 40 try{ 41 mailsender.send(preparator); 42 } 43 catch(MailException ex) { 44 //log it and go on 45 System.err.println(ex.getMessage()); 46 } 47 } 48 } |
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 3 "http://www.springframework.org/dtd/spring-beans.dtd"> 4 5 <beans> 6 <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 7 <property name="host"> 8 <value>smtp.163.com</value> 9 </property> 10 <property name="username"> 11 <value>username</value> 12 </property> 13 <property name="password"> 14 <value>password</value> 15 </property> 16 <property name="javaMailProperties"> 17 <props> 18 <prop key="mail.smtp.auth">true</prop> 19 <prop key="mail.smtp.timeout">25000</prop> 20 </props> 21 </property> 22 </bean> 23 24 <bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage"> 25 <property name="from"> 26 <value>Email</value> 27 </property> 28 <property name="subject"> 29 <value>标题</value> 30 </property> 31 <property name="text"> 32 <value>内容</value> 33 </property> 46 </bean> 47 48 <bean id="orderManager" class="cn.cityyouth.service.impl.OrderManagerImpl"> 49 <property name="mailsender"> 50 <ref bean="mailSender" /> 51 </property> 52 <property name="message"> 53 <ref bean="mailMessage" /> 54 </property> 55 </bean> 56 57 </beans> |
1 package cn.cityyouth.web.action; 2 3 import javax.servlet.http.HttpServletRequest; 4 import javax.servlet.http.HttpServletResponse; 5 import org.apache.struts.action.ActionForm; 6 import org.apache.struts.action.ActionForward; 7 import org.apache.struts.action.ActionMapping; 8 import org.apache.struts.action.ActionMessage; 9 import org.apache.struts.action.ActionMessages; 10 import com.test.service.OrderManager; 11 12 public class SendMailAction extends BaseAction { 13 14 /** 15 * Method execute 16 * 17 * @param mapping 18 * @param form 19 * @param request 20 * @param response 21 * @return ActionForward 22 */ 23 public ActionForward execute(ActionMapping mapping, ActionForm form, 24 HttpServletRequest request, HttpServletResponse response) { 25 OrderManager omi=(OrderManager)this.getBean("orderManager"); 26 String useremail="123@163.com"; 27 omi.placeOrder(useremail); 28 } 29 } |
自由广告区 |
分类导航 |
邮件新闻资讯: IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮 电子邮箱 | 反垃圾邮件|邮件客户端|网络安全 行业数据 | 邮件人物 | 网站公告 | 行业法规 网络技术: 邮件原理 | 网络协议 | 网络管理 | 传输介质 线路接入 | 路由接口 | 邮件存储 | 华为3Com CISCO技术 | 网络与服务器硬件 操作系统: Windows 9X | Linux&Uinx | Windows NT Windows Vista | FreeBSD | 其它操作系统 邮件服务器: 程序与开发 | Exchange | Qmail | Postfix Sendmail | MDaemon | Domino | Foxmail KerioMail | JavaMail | Winwebmail |James Merak&VisNetic | CMailServer | WinMail 金笛邮件系统 | 其它 | 反垃圾邮件: 综述| 客户端反垃圾邮件|服务器端反垃圾邮件 邮件客户端软件: Outlook | Foxmail | DreamMail| KooMail The bat | 雷鸟 | Eudora |Becky! |Pegasus IncrediMail |其它 电子邮箱: 个人邮箱 | 企业邮箱 |Gmail 移动电子邮件:服务器 | 客户端 | 技术前沿 邮件网络安全: 软件漏洞 | 安全知识 | 病毒公告 |防火墙 攻防技术 | 病毒查杀| ISA | 数字签名 邮件营销: Email营销 | 网络营销 | 营销技巧 |营销案例 邮件人才:招聘 | 职场 | 培训 | 指南 | 职场 解决方案: 邮件系统|反垃圾邮件 |安全 |移动电邮 |招标 产品评测: 邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端 |