邮件发送简单例子-jsp文件

2016-01-29 12:04 43 1 收藏

邮件发送简单例子-jsp文件,邮件发送简单例子-jsp文件

【 tulaoshi.com - Java 】

  MailExample.jsp

<html
<head
<titleJSP JavaMail Example </title
</head

<body

<%@ page import="java.util.*" %
<%@ page import="javax.mail.*" %
<%@ page import="javax.mail.internet.*" %
<%@ page import="javax.activation.*" %

<%
String host = "yourmailhost";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;

// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");

Session mailSession = Session.getDefaultInstance(props, null);

// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
mailSession.setDebug(sessionDebug);

// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(mailSession);

msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.
Transport.send(msg);

out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");

%
</table
</body
</html

 

来源:http://www.tulaoshi.com/n/20160129/1484488.html

延伸阅读
CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT        VARCHAR2,                                     &nb...
标签: PHP
  测试过的环境   win2000/IIS linux/apache win2000 下的 apache 没有成功!不知道为什么!!! <? echo "你会看到这个技术的前景!哈哈!...什么?没看到,刷新一次看看!! 看到了吧!!"; $i = 1;   for($j=0;$j<500;$j++)print(" "); //这一行就是不用刷新页面就能显示的部分...
标签: PHP
  一个简单的自动发送邮件系统     php的另一个强大的特征就是他有能通过html的表单修改变量的能力,通过这些变量,我们可以实现很多任务,包括象:发送wed-based的邮件,把信息输出给屏幕,从数据库中读取和传递数据。下面让我们构建一个小型的自动发送邮件系统,来演示这个能力。     让我们...
标签: Web开发
代码如下: ?xml version="1.0" encoding="UTF-8" ? !DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd" %@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"% %@ page import="java.net.*"% % String location = ""; String location...
标签: ASP
  Click here to copy the Code to your clipboard (Only for IE Users) 'Declare Variables Dim CDONTSObj, MessageBody 'Create the CDONTS object Set CDONTSObj = Server.CreateObject("CDONTS.NewMail") 'To Address CDONTSObj.To = "info@scriptmate.com" 'From Address CDONTSObj.From = "you@yours...

经验教程

15

收藏

45
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部