zoukankan      html  css  js  c++  java
  • 使用JavaMail发送SMTP认证的邮件给多个收信人


    /*
    * SMTPAuth.java
    *
    * Created on 2005年11月17日, 下午11:30
    */

    package com.jointforce;

    import javax.mail.*;
    import javax.mail.internet.*;
    import java.io.*;
    import javax.activation.*;
    import java.util.*;

    /**
    *
    @author  eric.cookie
    */
    public class SMTPAuth {
        
        
    /** Creates a new instance of SMTPAuth */
        
    public SMTPAuth() {
        }
        
        
    /**
         * 
    @param args the command line arguments
         
    */
        
    public static void main(String[] args) {
            
    // TODO code application logic here
            String to1 = "xxxx@xxxx.com";
            String to2 
    = "xxxx@xxxx.com";
            String to3 
    = "xxxx@xxxx.com";
            String to4 
    = "xxxx@xxxx.com";
            String to5 
    = "xxxx@xxxx.com";
            String to6 
    = "xxxx@xxxx.com";
            
            String from 
    = "zzzz@zzzz.com";
            String subject 
    = "Test JavaMail";
            
            Properties props 
    = System.getProperties();
            props.put(
    "mail.smtp.auth""true");
            props.put(
    "mail.smtp.host""smtp.jointforce.com.cn");
            
            SmtpAuthenticator sa 
    = new SmtpAuthenticator();
            Session sess 
    = Session.getInstance(props, sa);
            sess.setDebug(
    true);
            
            
    try {
                Message msg 
    = new MimeMessage(sess);
                msg.setFrom(
    new InternetAddress(from));
                msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to1, 
    false));
                msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to2, 
    false));
                msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to3, 
    false));
                msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to4, 
    false));
                msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to5, 
    false));
                msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to6, 
    false));
                msg.setSubject(subject);
                msg.setSentDate(
    new Date());
                msg.setText(
    "Hello World!\nSecond Line text\nend");
                Transport.send(msg);
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
        }
        
    }

    class SmtpAuthenticator extends Authenticator {
        
    protected PasswordAuthentication getPasswordAuthentication() {
            
    return new PasswordAuthentication("username_to_login_mailbox""password_to_login_mailbox");
        }
    }
  • 相关阅读:
    ccs元素分类 gcelaor
    webkit Safari的样式库
    “Zhuang.Data”轻型数据库访问框架(二)框架的入口DbAccessor对象
    “Zhuang.Data”轻型数据库访问框架(一)开篇介绍
    一个基于Dapper的DbContext封装
    打造比Dictionary还要快2倍以上的字查找类
    .Net core 的热插拔机制的深入探索,以及卸载问题求救指南.
    字符串类型的自动转换与识别
    最近发现的.net core中的一些bugs
    从项目经理的角度看.net的MVC中Razor语法真的很垃圾.
  • 原文地址:https://www.cnblogs.com/super119/p/1935020.html
Copyright © 2011-2022 走看看