简体   繁体   English

java批量电子邮件发件人

[英]java bulk email sender

I need to design an application in java which can send like 200-300 mails/sec. 我需要在java中设计一个可以发送200-300邮件/秒的应用程序。 How to get it done. 如何完成它。 I tried the simple Transport.send() which sends one mail at a time but that takes around 2-3 secs in itself. 我尝试了简单的Transport.send(),它一次发送一封邮件,但本身大约需要2-3秒。 Also will google smtp allow me to send this much number of mails per second ?! google smtp也允许我每秒发送这么多邮件吗? How to implement something like batch mail sending or can something like multi-threading help? 如何实现批量邮件发送之类的东西或多线程帮助?

Transport.send() is not an efficient way to send mass mails as it will open fresh connection for each message. Transport.send()不是发送群发邮件的有效方式,因为它会为每条邮件打开新连接。 Average time taken for each message is around 4 seconds. 每条消息的平均时间约为4秒。

Try below code: 试试以下代码:

Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator() {  
        protected PasswordAuthentication getPasswordAuthentication() {  
            return new PasswordAuthentication("FROM","PASSWORD");  
        }  
    });
Transport transport = session.getTransport("smtp");
transport.connect();
try{
   for(Message m : messages) {
   transport.sendMessage(m, m.getAllRecipients()); // time decreased to 2 second/message
   }
}finally {
t.close();
}

Further you can try implementing using ThreadPool having fixed number of Thread depending upon the system you are having. 此外,您可以尝试使用具有固定数量Thread的ThreadPool,具体取决于您拥有的系统。

Yes, you need a multithreaded server. 是的,您需要一个多线程服务器。 As you wrote, you will use about 1000 threads for sending, that is feasible on any hardware from a CPU performance viewpoint, but you have to have adequate memory too. 正如您所写,您将使用大约1000个线程进行发送,从CPU性能角度来看,这在任何硬件上都是可行的,但您也必须有足够的内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM