Java Mail API and its application-implementation of a Mail list server (IV) (posting)

Source: Internet
Author: User
Tags email account mail account
Appendix: ListServer. java
* ListServer provides the basic mail list service: reads all the new mails of the specified email account and forwards the emails
* The format of the email account in all email accounts (subscribers) specified in the emailListFile file. emailListFile
* One email account for each row.
Import java. util .*;
Import java. io .*;
Import javax. mail .*;
Import javax. mail. internet .*;
Import javax. activation .*;
Public class Class1
Private static final String INBOX = "INBOX", POP_MAIL = "pop3", SMTP_MAIL = "smtp ";
Private boolean debugOn = false;
Private String _ smtpHost = null,
_ Pop3Host = null,
_ User = null,
_ Password = null,
_ EmailListFile = null,
_ FromName = null;
Private InternetAddress [] _ toList = null;
// Main (): creates and starts a ListServer instance.
Public static void main (String args [])
Throws Exception
// Check input parameters
If (args. length <6)
System. err. println ("Usage: java ListServer SMTP server POP3 server POP3 account POP3 account password subscriber list file check cycle (minutes) sender name ");
System. exit (1 );
// Assign the command line parameter to the corresponding variable
String smtpHost = args [0], // smtp server
Pop3Host = args [1], // pop3 server
User = args [2], // pop3 email account
Password = args [3], // pop3 mail account password
EmailListFile = args [4], // subscriber list file
FromName = null; // sender name
Int checkPeriod = Integer. parseInt (args [5]); // New Mail check cycle
If (args. length> 6)
FromName = args [6];
// Create a ListServer instance to process new emails cyclically
ListServer ls = new ListServer ();
Ls. setDebug (false );
While (true)
Ls. debugMsg ("ListServer startup ...");
Ls. process (smtpHost, pop3Host, user, password, emailListFile, fromName );
Ls. debugMsg ("ListServer pause (rest" + checkPeriod + "minutes )");
Thread. sleep (checkPeriod * 1000*60 );
// Process (): check the new email and call processMsg () to process a single email.
Public void process (String smtpHost, String pop3Host, String user, String password, String emailListFile, String fromName)
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.