javaMail simple application

2010-04-29  来源:本站原创  分类:Java  人气:191 

import javax.mail .*;
import java.util .*;
import javax.mail.internet .*;
public class Mail_Sender (
public void send (String email, String username, String password)
(
Properties p = System.getProperties ();
/ / Set the SMTP server
p.setProperty ("mail.smtp.host", "smtp server");
/ / Verify SMTP
p.put ("mail.smtp.auto", "true");
Session s = Session.getInstance (p);
/ / See run-time information
/ / S.setDebug (true);
/ / Create a new message from the Mail Session object
MimeMessage mm = new MimeMessage (s);
try
(
/ / Sender
InternetAddress from = new InternetAddress ("From Address");
mm.setFrom (from);

/ / Recipient
InternetAddress to = new InternetAddress (email);
mm.setRecipient (Message.RecipientType.TO, to);

/ / Message Title
mm.setSubject ("title");
String content = "Dear User:" + username + ", your new password is:" + password + ", please take good care of!";

/ / Message content
mm.setContent (content, "text / html; charset = UTF-8");

/ / Save
mm.saveChanges ();

Transport tr = s.getTransport ("smtp");

/ / Smtp authentication is used to send the message you want the name of the mailbox password
tr.connect ("smtp server", "username", "password");

/ / Send
tr.sendMessage (mm, mm.getAllRecipients ());
tr.close ();
) Catch (Exception e)
(
e.printStackTrace ();
)
)
)

相关文章
  • javaMail simple application 2010-04-29

    import javax.mail .*; import java.util .*; import javax.mail.internet .*; public class Mail_Sender ( public void send (String email, String username, String password) ( Properties p = System.getProperties (); / / Set the SMTP server p.setProperty ("m

  • Ext.getCmp ("id") simple application 2010-06-20

    <%@page contentType="text/html" pageEncoding="UTF-8"%> <% request.setAttribute("base", request.getContextPath()); %> <html> <head> <meta http-equiv="Content-Type" content="text/html;

  • [Change] PowerDesigner12 simple application 2010-08-02

    [Transfer from: http://www.cnblogs.com/kay/archive/2007/06/07/774361.html ] PowerDesigner has not the familiar, has frequently written, many have asked this tool, so easy to learn a bit this afternoon. First, create a conceptual model 1. In File, sel

  • FreeMarker simple application 2010-08-30

    Chapter FreeMarker simple application of a simple example of 1, create a Web application: freeMarker, import reemarker-2.3.16 \ lib \ freemarker.jar 2, create a Servlet: ActionServlet.java package com.zh.servlet; import ... ... ... ...; public class

  • Subversion simple application using Redmine account verification. Advanced applications, and optimization 2010-11-08

    This is the original: http://www.himysql.com/vcs/subversion-redmine-advance.html I. Introduction Redmine is a set of open source, free cross-platform project management system, is the rising star of the project management community. Is a small develo

  • GridView custom paging, radio. Multiple selections. Sort. From the simple application of additional 2011-01-05

    VS2005 in the GridView on a custom paging, radio, checkbox, sorting, since the addition of a simple application. Multiple choice, only when all the selected "multiple choice" was selected. Photo Effect: [See Annex] Simple example, the code is as

  • Subversion uses a simple application Redmine account verification. Advanced applications and optimization 2010-11-08

    This is the original: http://www.himysql.com/vcs/subversion-redmine-advance.html I. Introduction Redmine is a set of open source, free cross-platform project management system, project management community is a rising star. Is a small development tea

  • Simple application of Oracle Spatial 2010-09-17

    2005, when it used this thing, but to complete the project and leave it at that time, did not record the number of operations, has spent about two days, recording about a simple application of the steps right. -- Build the test table create table tes

  • JavaMail simple to use and instructions 2010-03-29

    SMTP: Simple Mail Transfer Protocol (Simple Mail Transfer Protocol, SMTP) defined by RFC821, which defines mechanisms for sending messages in JavaMail environment, the procedure will be based on JavaMail and Internet service providers ISP (internet S

  • Axis2 deployment WebService ----- Simple Application 2010-03-29

    First, tell us the application's business logic is very simple to suit the client side to send a user name of weapons, and then the server-side under the user name returned, the person's details. 1): First of all to write a service weapon-side servic

  • (Reprinted) javamail simple example of sending mail 2010-07-09

    Today learned about JavaMail, javamail to send the message really is a rather troublesome problem. For later convenience, himself wrote a section of code, labeled jar package for later use. Ha ha The following three sections of the code is my all cod

  • MINA build on a simple application of high-performance NIO 2010-08-16

    (Change) mina is a very good C / S architecture java server, here turn a paper on the use of its experience. Preface MINA Trustin Lee is the latest production of the Java communications framework. The main role of the communications framework of the

  • pushlet simple application 2010-09-04

    Pushlet made recently applied projects, following the application of a simple idea that what I, as pushlet principle, a Web search everywhere, and I do not say this again. First, the proposed front-end using ajax version, because the application up a

  • Mysql Memory simple application of the engine 2010-10-05

    memory storage engine (also known as the old version of heap storage engine), suggests that it is stored in memory all the data, it has the following two distinct features: Store data in memory, very high speed; disappeared after the closure of all t

  • JQuery simple application 2010-11-19

    Select all Invert Selection Application: <a href="#"> Select All </ a> / <a href="#"> anti-choice </ a> $ (Document). Ready (function () { $ (". All_choice"). Click (function () { $ ('Input [name = che

  • GroovyOnGrails simple application 2007-09-22

    Create a simple Web application (based on mysql database) 1. Download and install Groovy and Grails Groovy: http://groovy.codehaus.org/Download Grails: http://grails.org/Installation 2. Creating database tables: DROP TABLE IF EXISTS `ebxmlrr`. `Comic

  • Ext simple application (a)-SSH2 + Ext2 data page display 2009-10-20

    I wrote a relatively simple demo, but the most simple query page, after the change will continue to increase functionality. IE7 and Firefox through testing. Or please view the specific code is better. Ext for the use of the preparatory work needed in

  • DWR introduction and simple application 2010-03-29

    What is DWR (Direct Web Remote)? DWR is an AJAX solution! DWR consists of a java library, and a set of javascript, allows us to use a very simple way to use javascript on the page directly call the java object back! DWR's javascript library consists

  • View, a simple application 2010-03-06

    Simplify the structure of the three tables on the map, and now need to t_customer table pname field all the updates for the t_person table corresponds to the value of pname. I use basic SQL (update and select) statement did not realize that if any me

  • Javascript simple application of testing methods and speeds (rpm) 2010-04-08

    Very slow speeds, but may open the Flash is a very painful thing, especially in the dawn of Silverlight, the technology may be of some use Specific code as follows <SCRIPT LANGUAGE="JavaScript"> var starttime = new Date() </SCRIPT> &