本文发表在 rolia.net 枫下论坛You use randomaccessfile class to read in the file. Using stringtokenizer to break up the file and loop through the emails as the asp example.
Class needed:
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;
method for send out emails:
public static void sendMail(String rec,String recCC,String sender,String sub,String mes) {
try {
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
Session session = Session.getDefaultInstance(props,null);
session.setDebug(false);
Message msg = new MimeMessage(session);
Address from = new InternetAddress(sender);
msg.setFrom(from);
Address recipient = new InternetAddress(rec);
msg.setRecipient(Message.RecipientType.TO, recipient);
if (recCC != "") {
Address recipientCC = new InternetAddress(recCC);
msg.setRecipient(Message.RecipientType.CC, recipientCC);
}
msg.setSubject(sub);
msg.setText(mes);
Transport.send(msg);
}
catch (MessagingException e) {
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
Class needed:
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.*;
method for send out emails:
public static void sendMail(String rec,String recCC,String sender,String sub,String mes) {
try {
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
Session session = Session.getDefaultInstance(props,null);
session.setDebug(false);
Message msg = new MimeMessage(session);
Address from = new InternetAddress(sender);
msg.setFrom(from);
Address recipient = new InternetAddress(rec);
msg.setRecipient(Message.RecipientType.TO, recipient);
if (recCC != "") {
Address recipientCC = new InternetAddress(recCC);
msg.setRecipient(Message.RecipientType.CC, recipientCC);
}
msg.setSubject(sub);
msg.setText(mes);
Transport.send(msg);
}
catch (MessagingException e) {
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net