Unten finden Sie ein Tool zum Empfangen von E -Mails, was ein bisschen lang ist! ! !
public class recivemail {private mimemessage msg = null; msg = msg; ] adress = (InternetDress []) msg.getFrom (); ); und Informationen. Abhängig von den übergebenen Parametern "an"-> Empfänger, "CC"-> CC-Adresse, "BCC"-> Client-Adresse * @param typ (String -Typ) löscht MessagingException, UnsupportEnEdEnCodingException {String mailAddr = ""; ) || addrtype.equals ("bcc") {if (addrtype.equals ("to") {address = (InternetAddress []) msg.getRecipients (Message.RecipientType.to); "CC") {adress = (InternetAddress []) msg.getRecipients (Message.RecipientType.cc); RecicentType.bcc); mail = ""; Decodetext (Personal); Typ! ");} Return mailAddr;} / ** * Holen Sie sich den E -Mail -Betreff * @return * @throws UnsupportedenCodingException * @throws MessagingException * / public String getUntject () löscht die nicht unterstützte AnscodingException, MessagingException {String Subjekt ="; .DecodeText (msg.getSubject ()); ) MessagingException {Datum sendDate = msg.getSentdate (); () {return bodyText.toString (); * @Throws MessagingException * @throws ioException */ public void GetMailContent (Teil) MessagingException, IOException {String contentType = part.getContentType (); nameIndex! = -1) {conname = true; part.getContent ()); /*")) {MultiPart multiPart = (MultiPart) part.getContent (); int count = multiPart.getCount (); für (int i = 0; i <count; i ++) {getmailContent (multiPart.getBodypart (i)) ; RECHEN SIE TRUE ! = null) {ReplySign = true; } / ** * Bestimmen Sie, ob diese Nachricht gelesen wurde. = false; i = 0; i <flag.Length; i ++) {if (Flag [i] == Flags.flag.seen) {isNew = true; break;}} return isNew; Falsch; int i = 0; i <count; i ++) {bodypart bodypart = multiPart.getBodypart (i); | Disposition.equals (part.inline)) {flag = true; ; }}}}} else if (part.ismetype ("message /rfc822") {flag = isContainattch ((Teil) Part.getContent ()); @Throws MessagingException *@throws ioException */ public void saveatTchment (Teil Teil) löscht MessagingException, IOException {String FileName = ""; (); disposition.equals (part.Attachment) || dispoStion.equals (part.inline)) {Dateiname = parart.getFileName (); = Mimeutility.DecodeText (Dateiname); ); }}} else if (part.ismImetype ("message/rfc822") {saveatTchment ((Teil) Part.getContent ()); GetAveTtchPath () {SaveatTchPath zurückgeben; DateFormate */ public void setDateFormate (String DateFormate) {this.dateFormate = DateFormate; IOException {String osname = system.getProperty ("os.name"); .Indexof ("Win")! =-1) {sepatror = "//"; {sepatror = "/"; null; .Write (c); .printstacktrace (); ------------ Start ------- ------------------ "); System.out.println (" Nachricht " +i+"Betreff:"+getUbject ()); ()) boolean Flag = IsContainattch (Teil); ) GetMailContent (Teil); Teil); ---------------- ");}}
Es gibt verschiedene Möglichkeiten, E -Mail -Empfang und Werkzeugverbrauch zu schreiben! :
Ich habe viele andere Codes im Internet gelesen.
Wenn die eingehende E -Mail 163 Mailbox ist, müssen Sie sich zunächst bei 163 Mailbox anmelden, um ihn einzurichten und den POP3 -Service zu aktivieren. Ich kenne andere E -Mail -Adressen noch nicht.
public static void main (String [] args) löst Ausnahme aus {// Hostname, Protokoll, Benutzername und Kennwort des POP3 -Servers, das mit dem POP3 -Server -String -String -Pop3server = "Pop.163.com" angeschlossen ist. pop3 "; String user =" userername "; String pwd =" Passwort "; // Erstellen Sie ein Eigenschaftenobjekt mit spezifischen Verbindungsinformationseigenschaften props = new Properties (); props.setProperty (" mail.store.Protocol ", Protocol); props.setProperty ("mail .pop3.host", pop3server); das Store-Objekt und eine Verbindung zum POP3 Server Store = Session.getStore (); store.getFolder ("Posteingang"); = 0; .schließen(); }