java 批量电子邮件期间的 javamail 与 sendmail 性能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1780112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javamail vs sendmail performance during bulk email
提问by WellieeGee
I'm writing a Java mass emailer application to send out emails to send between 50,000 to 100,000 a day to users.
我正在编写一个 Java 群发电子邮件应用程序来发送电子邮件,每天向用户发送 50,000 到 100,000 封电子邮件。
The current plan is to delegate the sending to delegate to sendmail (on the local unix server).
当前的计划是将发送委托给 sendmail(在本地 unix 服务器上)。
From our testing sendmail is sending a maximum of 5 emails per second.
根据我们的测试,sendmail 每秒最多发送 5 封电子邮件。
Would JavaMail be a faster option?
JavaMail 会是一个更快的选择吗?
Does anyone know what a faster way to send emails. We want to get this process out as quick as possible.
有谁知道发送电子邮件的更快方法。我们希望尽快完成这个过程。
Edit: BTW, a pdf will be attached too
编辑:顺便说一句,pdf也会附上
回答by skaffman
You're not comparing like with like. JavaMail talks SMTP to hand off to the nearest mail server. Sendmail is a Mail Transfer agent responsible for routing emails to their destination.
你不是在比较喜欢。JavaMail 与 SMTP 通信以移交给最近的邮件服务器。Sendmail 是负责将电子邮件路由到目的地的邮件传输代理。
A common setup is a java application using JavaMail to relay email via SMTP to a Sendmail server. The two are not competitors, they're used together. A sendmail server should be able to accept deliveries from javamail faster than any java application can produce them, but then it delivers them asynchronously at its own rate.
一个常见的设置是一个 Java 应用程序,它使用 JavaMail 通过 SMTP 将电子邮件中继到 Sendmail 服务器。两者不是竞争对手,它们是一起使用的。sendmail 服务器应该能够以比任何 Java 应用程序生成它们的速度更快地接受来自 javamail 的传递,但随后它会以自己的速率异步传递它们。
回答by Andre
This might be a little too old, but I just managed to get javamail and sendmail to work together. It's actually super easy and I felt stupid for not getting it done faster...
这可能有点太旧了,但我只是设法让 javamail 和 sendmail 一起工作。这实际上非常简单,我为没有更快地完成它而感到愚蠢......
Let's ignore sendmail for a bit here. How can we send an e-mail through javamail? There are tons of tutorials online, but here's how it's done:
让我们在这里暂时忽略 sendmail。我们如何通过javamail发送电子邮件?网上有很多教程,但这是如何完成的:
- Create your session with the appropriate authenticator;
- Create your MimeMessage object (here's where you add all your recipient addresses);
- Call Transport.send() with your message.
- 使用适当的身份验证器创建您的会话;
- 创建你的 MimeMessage 对象(这里是你添加所有收件人地址的地方);
- 使用您的消息调用 Transport.send()。
What if your SMTP server only sends emails up to 100 recipients (like mine)? That's when sendmail comes into play. You can think about sendmail as your own SMTP server. So install it first. If you're running Ubuntu (like me), just do:
如果您的 SMTP 服务器最多只向 100 个收件人(如我的)发送电子邮件怎么办?这就是 sendmail 发挥作用的时候。您可以将 sendmail 视为您自己的 SMTP 服务器。所以先安装。如果您正在运行 Ubuntu(像我一样),请执行以下操作:
sudo apt-get install sendmail
The installation ends pretty quickly. After that, sendmail is ready to be used. I didn't bother configuring any type of authentication or whatsoever, but it's probably a good idea to do so if your server will have a public IP on the internet. Now, instead of pointing your java code (that uses javamail) to your SMTP server, just point it to localhost (or whatever machine you just installed sendmail).
安装很快结束。之后,sendmail 就可以使用了。我没有费心配置任何类型的身份验证或其他任何东西,但如果您的服务器在互联网上有一个公共 IP,那么这样做可能是个好主意。现在,不要将您的 java 代码(使用 javamail)指向您的 SMTP 服务器,只需将它指向 localhost(或您刚刚安装了 sendmail 的任何机器)。
You can even test your sendmail installation with your regular mail client (thunderbird, outlook, windows mail or whatever floats your boat). Just configure your SMTP server to the machine you installed sendmail. Guess what? It works!
您甚至可以使用您的常规邮件客户端(thunderbird、outlook、windows 邮件或任何漂浮在您的船上的东西)来测试您的 sendmail 安装。只需将您的 SMTP 服务器配置为您安装了 sendmail 的机器。你猜怎么着?有用!
Just don't use this to send emails to the entire world... ;)
只是不要使用它向全世界发送电子邮件......;)
回答by Priyank Jain
If we use Tranport.send() - Static method, in Java mailer for sending the mails,this method does the handshaking, for each of the email address present in the list. (Handshaking is: Request from Client -> Response from the server -> Acknowledgement. ), i.e. each time it closes the connection with the SMTP mail server. Here is way to increase the performance.., by which we can do handshaking only one time, and it greatly reduces the SMTP traffic. And send the mail to all recipients in one shot, Pl refer SCR#A for SMTP traffic for this scenario. Here is the code for reference,
如果我们使用 Tranport.send() - 静态方法,在用于发送邮件的 Java 邮件程序中,此方法会为列表中的每个电子邮件地址执行握手。(握手是:Request from Client -> Response from the server -> Acknowledgement。),即每次关闭与SMTP邮件服务器的连接。这是提高性能的方法..,我们可以只进行一次握手,并且大大减少了 SMTP 流量。并一次性将邮件发送给所有收件人,对于这种情况,请为 SMTP 流量参考 SCR#A。这是参考代码,
Instead of,
代替,
Transport.send(msg);
We should use below piece of code,
我们应该使用下面的代码,
msg.saveChanges(); // implicit with Transport.send()
Transport tr = session.getTransport("smtp");
tr.connect(smtphost, username, password);
msg.saveChanges(); // don't forget this
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
For sending bulk mails.
用于发送大量邮件。
Here you can see the network traffic using wire shark tool..
在这里,您可以使用线鲨工具查看网络流量。
What is needed, to setup this with a Mail server. -->A local m/c installed with Wire shark tool and Apache tomcat 6.0 and it should be able to ping your mail server say relay.abcxyz.com
需要什么,用邮件服务器设置它。-->安装了Wireshark工具和Apache tomcat 6.0的本地m/c,它应该能够ping你的邮件服务器说relay.abcxyz.com
Now run the test bed for both the cases.
现在为这两种情况运行测试台。
回答by Thorbj?rn Ravn Andersen
First of all, I suppose this is for legitimate reasons and not spamming?
首先,我想这是出于正当理由而不是垃圾邮件?
Sendmail is very, very fast for sending emails. What is not so fast is the DNS lookups needed to locate the mailservers for the domain - you need to do a MX query for each - and that would fit fine with the 5 messages pr second you report.
Sendmail 发送电子邮件的速度非常快。不是那么快的是定位域的邮件服务器所需的 DNS 查找——您需要为每个服务器执行 MX 查询——这与您报告的每秒 5 条消息非常吻合。
When that is said, you would probably be best off with standard high-performance mailing list software where you construct the message with javamail and tell the mailing list software to send it to everybody. Also ally with e.g. Google Mail as they scale well, to actually get them all sent. Google Apps for Java can allow you to send from within the Google cloud.
话虽如此,您可能最好使用标准的高性能邮件列表软件,您可以在其中使用 javamail 构建消息并告诉邮件列表软件将其发送给所有人。还与例如 Google Mail 结盟,因为它们可以很好地扩展,实际上可以将它们全部发送。Google Apps for Java 可以让您从 Google 云内部发送。
Back in ancient history when I worked with that Majordomo worked fine with sendmail. ezmlm works well with qmail (but is probably abandoned by now) and I think mjmlm works well with postfix.
回到古代,当我与那个 Majordomo 一起工作时,用 sendmail 工作得很好。ezmlm 与 qmail 配合良好(但现在可能已被放弃),我认为 mjmlm 与 postfix 配合良好。

