JavaMail Send Mail - Exendmail

xiaoxiao2021-03-06  42

Package com.mail;

Import org.apache.log4j.logger;

Import java.util. *; import java.io. *; import org.apache.log4j.logger; import javax.mail. *; import javax.mail.internet. *; import javax.activation. *;

/ ** @Author administrator * Send a message * / public class sendmail {static logger logger = logger.getlogger (sendmail.class); // Define String to = "" ", from =", etc. , Host = "", filename = "", messagetext = ", subject =" "; boolean debug = false; // Save the sending file name vector vfile = new vector (10, 10); // Save the sending body VECTOR VMSG = New Vector (10, 10); public sendmail () {} public sendmail (String to, string from, string smtpserver, string subject) {// Initializing Recipient, sender, theme this.to = TO; This.host = from; this.host = SMTPSERVER; this.subject = Subject;} // collects additional file public void attachfile (String FNAME) {vfile.addelement (fname);} // Collection Mail Public Void SetMessage (String MSG) {vmsg.addelement (msg);} // Setup debug logo public void setbug (boolean debug) {this.debug = debug;} // message send function public boolean startsend () {property pROPS = system.getProperties () ProPS.PUT ("mail.smtp.host", host); session session = session.getDefaultInstance (props, null); session.SetDebug (debug); try {// creates a message and initializes the messages Element mimeMessage msg = new mimeMessage (session); msg.setFrom (new internetdress (from)); InternetAddress [] AddR ess = {new InternetAddress (to)}; msg.setRecipients (Message.RecipientType.TO, address); msg.setSubject (subject); // Add the message part of the newly created MultipartMultipart mp = new MimeMultipart (); // Message Enumeration emsg first portion of content = vmsg.elements ();. while (emsg.hasMoreElements ()) {messagetext = emsg.nextElement () toString (); MimeBodyPart mbp1 = new MimeBodyPart (); mbp1.setText (messagetext); mp .addBodyPart (mbp1);} vmsg.removeAllElements (); Enumeration efile // second part of the message content = vfile.elements (); while (efile.hasMoreElements ()) {MimeBodyPart mbp2 = new MimeBodyPart (); filename = efile .NexTelement (). Tostring (); FileDataSource fds =

转载请注明原文地址:https://www.9cbs.com/read-52589.html

New Post(0)