Java uses SMTP protocol to send mail

Source: Internet
Author: User

The example requires two packages: Mail.jar and Activation.jar, whose download address is:
Http://java.sun.com/products/javamail/downloads/index.html
Http://java.sun.com/javase/technologies/desktop/javabeans/jaf/downloads/index.html

Unzip after downloading, place Mail.jar and Activation.jar in the Lib folder in project, configure the environment variable for it, or add it to "libraries" in MyEclipse in "Java build Path".

Project has three classes: the Entry Class (Testjavamail), the Mail information Class (Mailbean), and the Send Message Class (SendMail)

Mailbean.java package test3;

Import Java.util.Vector;

public class Mailbean ... {

Private String to; Recipient
Private String from; Sender
Private String host; SMTP Host
Private String username; Sender's user name
private String password; Sender's password
Private String subject; Message subject
Private String content; Message body
vector<string> file; Multiple attachments
private String filename; File name of attachment

Public String Getto () ... {
return to;
}

public void Setto (String to) ... {
This.to = to;
}

Public String getfrom () ... {
return from;
}

public void Setfrom (String from) ... {
This.from = from;
}

Public String gethost () ... {
return host;
}

public void Sethost (String host) ... {
This.host = host;
}

Public String getusername () ... {
return username;
}

public void Setusername (String username) ... {
This.username = Username;
}

Public String GetPassword () ... {
return password;
}

public void SetPassword (String password) ... {
This.password = password;
}

Public String getsubject () ... {
return subject;
}

public void Setsubject (String subject) ... {
This.subject

Related Article

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.