Вопрос

My email code works well when I just send an email to a few people, but when I sending to all users(177) in contact, I got this error:

[ERROR]  - org.apache.commons.mail.EmailException: Sending the email to the following server failed : hlrdwd.com:25

The code is below:

HtmlEmail email = new HtmlEmail();
        email.setCharset("utf-8");
        if (vo.getContent() != null && vo.getContent().trim().length() > 0) {
            email.setHtmlMsg(vo.getContent());
        } else {
            email.setHtmlMsg("   ");
        }
        email.setSubject(vo.getTitle());
        email.setFrom(vo.getSender(), currentuname);
        email.setHostName(Property.getSmtp());
        List<Map<String, String>> toList = mm.formatAddress(vo
                .getReceiver());
        if (toList != null) {
            for (int i = 0; i < toList.size(); i++) {
                Map<String, String> tMap = toList.get(i);
                email.addTo(tMap.get(mm.KEY_EMAIL), tMap.get(mm.KEY_NAME));
                System.out.println(tMap.get(mm.KEY_EMAIL));
            }
        }
        email.setAuthentication(currentuser, password);

        String messageid = email.send();

I google this and add email.setTLS(true);, but still can not work. Waiting your help!

Это было полезно?

Решение

The problem is that the receiving mail server doesn't like messages being sent to too many people at the same time. As a reference, postfix by default rejects messages with more than 50 recipients.

The simplest solution is to send multiple messages, rather than sending to everyone at once. In the extreme, you could send a message per user -- then you get the opportunity to customise the messages if you want, which also makes them less likely to be filtered as spam.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top