- 论坛徽章:
- 0
|
postMail函数如下,主要是 emailList是数组文件。调用的时候没有法用单个String。不知道应该怎么样调用。谢谢
- private static final String[] emailList = {"[email]xx@xx.com[/email]", "[email]xx@xx.com[/email]"};
- public static void main(String args[]) throws Exception
- {
- SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication(); smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
- System.out.println("Sucessfully Sent mail to All Users");
- }
- public void postMail( String recipients[], String subject,
- //public void postMail( String recipients, String subject,
- String message , String from) throws MessagingException
- {
- boolean debug = false;
- //Set the host smtp address
- Properties props = new Properties();
- props.put("mail.smtp.host", SMTP_HOST_NAME);
- props.put("mail.smtp.auth", "true");
- Authenticator auth = new SMTPAuthenticator();
- Session session = Session.getDefaultInstance(props, auth);
- session.setDebug(debug);
- // create a message
- Message msg = new MimeMessage(session);
- // set the from and to address
- InternetAddress addressFrom = new InternetAddress(from);
- msg.setFrom(addressFrom);
- InternetAddress[] addressTo = new InternetAddress[recipients.length];
- for (int i = 0; i < recipients.length; i++)
- {
- addressTo[i] = new InternetAddress(recipients[i]);
- }
- msg.setRecipients(Message.RecipientType.TO, addressTo);
- // msg.setRecipient(Message.RecipientType.TO,toemail);
- // Setting the Subject and Content Type
- msg.setSubject(subject);
- msg.setContent(message, "text/plain");
- Transport.send(msg);
- }
复制代码
[ 本帖最后由 jiarry 于 2005-12-2 14:47 编辑 ] |
|