jsp sending mail (using mail server)

2010-06-21  来源:本站原创  分类:Web  人气:224 

jsp page (form page)

<form name="form1" method="post" action="email.jsp" onSubmit="return mailCheck()">
<table width="100%" height="225" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25"> Your Email:
<input type="text" name="fromUser" value="">
<font color="#FF0000"> * </ font> <span> fill your mailbox to receive messages such as: [email protected] </ span> </ td>
</ Tr>
<tr>
<td height="25"> Send Address:
<Input type = "text" name = "TOUSER" Value = " [email protected] "ReadOnly =" redaonly ">
</ Td>
</ Tr>
<tr>
<td height="25"> message subject:
<input type="text" name="subject">
<font color="#FF0000"> * </ font> <span> fill in your name and the candidate's positions, such as: seating candidates XX post </ span> </ td>
</ Tr>
<tr>
<td height="100" valign="top">
<FCK:editor BasePath="FCKeditor/" height="150" width="754" toolbarSet="Simple">
To paste your resume here </ FCK: editor> </ td>
</ Tr>
<tr>
<td height="25">
<input type="submit" name="Submit" value=" Submit ">
<input type="reset" name="Submit2" value=" Override ">
With <span> <font color="#FF0000"> * </ font> </ span> is required, please </ td>
</ Tr>
</ Table>
</ Form>

email.jsp page

<% @ Page language = "java" import = "java.util .*" pageEncoding = "gb2312"%>
< % @ page import = "javax.mail .*;"%>
<jsp:useBean scope="page" />

<%
String from = request.getParameter ("fromUser");
String to = request.getParameter ("toUser");
String subject = request.getParameter ("subject");
subject = new String (subject.getBytes ("iso8859-1"), "gb2312");
String body = request.getParameter ("context");
body = new String (body.getBytes ("iso8859-1"), "gb2312");
int i = MyMail.sendMail (from, to, subject, body);
if (i == 1)
(%>
<script type="text/javascript">
<! -
alert ("Message sent successfully !!!");
window.location.href = "/ indexServlet";
//-->
</ Script>
<%) Else
(%>
<script type="text/javascript">
<! -
alert ("Fail to send !!!");
window.location.href = "/ indexServlet";
//-->
</ Script>
<%
)
%>

email.java

package com.bf.isp.mail;

import java.util .*;

import javax.mail .*;

import java.io. *;
import javax.mail.internet .*;
import javax.activation .*;

public class Email (

public Email () (
super ();
)

public int sendMail (String fromeUser, String toUser, String subject,
String context) (
Session session;
/ / Create a MIME message object
MimeMessage message;
/ / Get system properties object
Properties props = System.getProperties ();
/ / Set smtp host
props.put ("mail.smtp.host", "smtp.jspinsider.com");
props.put ("mail.smtp.host", "127.0.0.1");
/ / Props.put ("mail.smtp.auth", "true");
/ / Get the message session object
session = Session.getInstance (props, null);
/ / Create a MIME message object
message = new MimeMessage (session);

try (
/ / Set sender
message.setFrom (new InternetAddress (fromeUser));
/ / Set the recipient
message.addRecipient (Message.RecipientType.TO, new InternetAddress (
"ToUser"));

/ / Set the message subject
message.setSubject (subject, "gb2312");
/ / Set the message body
/ / Message.setText (context);
/ / Set the time
message.setSentDate (new Date ());
/ / Set the content, the content into html content
message.setContent (context, "text / html; charset = utf8");

Transport transport = session.getTransport ("smtp");
transport.send (message);
return 1;
) Catch (MessagingException e) (
e.printStackTrace ();
e.getMessage ();
return 0;
)
)

)

相关文章
  • Creating a SAP shortcut for any transaction and sending it by mail 2010-11-02

    Refer to SAP wiki: http://wiki.sdn.sap.com/wiki/display/Snippets/Creating+a+SAP+shortcut+for+any+transaction+and+sending+it+by+mail Key Points: 1. Create the shortcut content for the required transaction CALL FUNCTION 'SWN_CREATE_SHORTCUT' EXPORTING

  • Linux: mail the mail and check 2011-08-02

    System receives the message will be saved in "/ var / spool / mail / [linux user name]" file. In linux, type mail, the conduct of the Inbox, and shows the twenty mailing list. At this point the command prompt as "&" unread messages

  • jsp sending mail (using mail server) 2010-06-21

    jsp page (form page) <form name="form1" method="post" action="email.jsp" onSubmit="return mailCheck()"> <table width="100%" height="225" border="0" cellpadding="0" ce

  • U-Mail sending and receiving mail server problems overseas break 2011-04-12

    With the rapid development of economic globalization of the world to import and export business for the support of many businesses benefit. The growing proportion of overseas business, a huge economic boost of the wave of Chinese enterprises. In the

  • You hava a mail from linux server~ 2010-12-14

    cat /var/spool/mail/root 可以查看下系统信息. 磁盘使用情况等等

  • c # winform mail. net mail 2010-07-30

    public void SendMailUseYeah () ( System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage (); msg.To.Add ("Write Address"); / / Msg.To.Add (""); / / Msg.To.Add (" [email protected] "); / * * Msg.To.Add (" [email protected] ");

  • JSP连接MySql/MS SQL Server/Oracle数据库连接方法[整理] 2014-02-24

    这个经常整理更新 JSP连接MySql数据库方法 首先先将MySql的数据库连接驱动拷贝到Tomcat/common/lib包下 下载mysql-connector-java-5.1.6.zip http://mysql.cs.pu.edu.tw/Downloads/Connector-J/mysql-connector-java-5.1.6.zip 配置Tomcat的虚拟目录-略 创建jdbcMySql.jsp页面 页面代码如下: <%@ page contentType="text/h

  • 在JSP中访问MS SQL Server数据库 2014-05-27

    下面介绍如何用SQL Server实现一个动态FAQ(常见问题及答案)网站. 首先建立一个数据库faq,其中的表faqs有字段id(int,自动增量,并设为主关键字).subject(varchar,200).answers(text).这个表中可以存放一些编程知识的常见问题及答案.然后,在Control Panel(控制面板)的ODBC Datasource模块中加入System DSN,取名faq,并指向faq数据库.创建一个JavaBean,名为faq.java,并保存在C:\JBuild

  • Let your own domain name with unlimited email (Google Mail, Tencent Mail, etc.) 2011-04-11

    When we have a own a website, have their own domain name, Although the space inside the mailbox service this feature, but still very limited. . To break through this limitation, we need to use E-mail to configure more of our domain mailbox. Informati

  • EXCHANGE SMTP status code control when sending mail 2011-05-13

    Non-delivery report (NDR) message to the sender report message delivery status of the system. This message is referred to as "delivery status notification," the general message information structure of the sub-categories. Delivery status notific

  • GCMail open green postal mail server, create a convenient and environmentally friendly business life 2011-07-17

    The competitive business mail market, the domestic mail service businesses have been offering a variety of corporate email, recently, GCMail announced the formal launch of a mail mail server software security escort green products "GCMail v8.0",

  • GCMail mail server and mail server which the traditional distinction 2011-07-05

    Recent users often ask: "GCMail mail server", but not very professional for some users, many of the current traditional business users are the wrong mail server down, or even many users to GCMail mail server with 263, Coremail, Winmail, CMail, S

  • Through the use javamail smtp server requires authentication to send mail 2010-04-09

    Use javamail to send mail, if the smtp server requires authentication, we need to inherit javax.mail.Authenticator themselves to implement a class that covers getPasswordAuthentication () Method returns a user name, password information, PasswordAuth

  • Use GCMail Server install mail server set up 2011-07-26

    GCMail is a smart full-featured mail server software , supporting SMTP, POP3, WebMail, multi-domain, certified letters, anti-spam, mail filtering, mail groups and other standard mail features, built-in world-class Kaspersky anti-virus engine, Bayesia

  • [Practice has proved that finishing line] CentOS 6 in the easy set up Apache James mail server 2011-09-23

    Reference 1 set up with Apache James mail server to send and receive e-mail practices (a) http://zhaipuhong.iteye.com/blog/213246 2. James + mysql http://godchenmeng.iteye.com/blog/516680 3. Apache James user information database to store and passwor

  • In the java EE 5.0 developed under the java mail problems encountered and solutions 2010-03-22

    Make a java EE recent small-scale projects, using a java EE 5.0, the project there is a module is to automatically send a message to the customer, so it is natural to develop using java mail. But the question on the hit, the code is not running the c

  • 2009-12-18 Chuan Chi podcast - Principles and java mail message development (transfer set) 2010-04-10

    Today is JAVAWEB last lesson, JAVAMAIL. E-mail in today's daily life has become one of the important means of communication, WEB applications in E-mail was used to communicate with the user the most important ways. Now all the major comprehensive web

  • javamail mail integrity code 2010-08-02

    Prerequisite: J2EE1.4 or Internet download mail.jar package com.mail; import java.util.Date; /** * Message class * @author Dave [email protected] */ public class Email{ public final static String TO="[email protected]"; public final static String FROM=

  • Spring Framework JavaMail package using synchronous or asynchronous real mail 2010-08-21

    Spring Framework JavaMail package using synchronous or asynchronous real mail Author: Zhang Jihao J2EE Simply put in the JDK on the expansion of the types of applications, standards, e-mail address is one of the important applications. Since it is st

  • Logistics Mail Relay + gateway solution 2011-07-27

    In the 21st century, global trade and cross-domain circulation of goods, and promote the rapid development of the logistics industry, has led to fierce competition in the logistics industry. How to improve logistics management efficiency, reduce supp