Send mail with JavaMail

Source: Internet
Author: User
/*
* File:Mail.java
* date:2005-2-28
* Author:fuweilin
* Project:
* Ver:
* Note:
* */
Package Com.toone.eg.common;
/**
* @author FUWLN
* @version 1.0
*/
Import java.util.*;
Import javax.mail.*;
Import javax.mail.internet.*;
Import javax.activation.*;
/**
* @author FUWL
*
* To change the template for this generated type comment go
* Window-preferences-java-code Generation-code and Comments
*/
public class Mail {
Private MimeMessage mimemsg; MIME Mail Object
Private session session; Mail Session Object
Private Properties props; System Properties
Private Boolean Needauth = false; Does SMTP require authentication
Private String username = ""; SMTP authenticated user name and password
Private String Password = "";
Private Multipart MP; Multipart objects, message content, headers, attachments, and so on are added to it before the MimeMessage object is generated
/**
*
*/
Public Mail () {
Setsmtphost ("smtp.163.com")://If no mail server is specified, obtain from the GetConfig class
Createmimemessage ();
}
Public Mail (String SMTP) {
Setsmtphost (SMTP);
Createmimemessage ();
}
/**
* @param hostName String
*/
public void Setsmtphost (String hostName) {
SYSTEM.OUT.PRINTLN ("Set system properties: Mail.smtp.host =" +hostname);
if (props = = null) props = System.getproperties (); Get System Properties Object
Props.put ("Mail.smtp.host", hostName); Setting up an SMTP host
}
/**
* @return Boolean
*/
public boolean createmimemessage ()
{
try{
System.out.println ("Ready to get mail Session Object!") ");
Session = Session.getdefaultinstance (props,null); Get mail Session Object
}
catch (Exception e) {
SYSTEM.ERR.PRINTLN ("An error occurred while getting the mail session Object!") "+e);
return false;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.