← Back to team overview

openerp-community team mailing list archive

E-Mail sending problems and questions about addons/mail/mail_mail.py

 

Hi,

[version 7.0-20131126-00264]

I came across a problem with email sending. When adding a message to a
project issue, only the first five followers got an email. There was
no error message in the web user interface, instead the user interface
shows, that the email has been send to all followers.

What happened?

 1. Instead of sending one email per message, one email per recipient
    is generated, in my case ten emails instead of one. This is wrong
    IMHO, because it is the task of the SMTP server to distribute the
    emails to all recipients. This is the main problem, I assume.

 2. The emails are delivered to the SMTP server, which throttles the
    traffic by not allowing more than five emails that fast. This leads
    to an in addons/base/ir/ir_mail_server.py:464 The exception is
    logged but invisible to the web interface user:
    SMTPServerDisconnted("Connection unexpectedly closed")

 3. The email iteration stops at that point, no further emails are
    tried for this message. If it not were for throttling, IMHO this
    again is wrong. One should at least try to sent out all emails.

 4. Independent of this doubts, I assume, that the actual loop sending
    out the email is not correct: A return value is saved inside the
    loop in `res` and used after the loop, i.e. the value is just
    overwritten and only the last value is used.

From addons/mail/mail_mail.py:

283 email_list = []
284 if recipient_ids:
285     for partner in self.pool.get('res.partner').browse(...
286         email_list.append(self.send_get_email_dict(...
287 else:
288     email_list.append(self.send_get_email_dict(...
...
291 res = None
292 for email in email_list:
293     msg = ir_mail_server.build_email(
294         email_from = mail.email_from,
295         email_to = email.get('email_to'),
...
307     res = ir_mail_server.send_email(cr, uid, msg,
308         mail_server_id=mail.mail_server_id.id, context=context)
309 if res:
310     mail.write({'state': 'sent', 'message_id': res})
311     mail_sent = True
312 else:
313     mail.write({'state': 'exception'})
314     mail_sent = False

IMHO, using the loop in line 292 is wrong. Instead one message should be
send out with the correct list of recipients, right?

Thanks in advance for any enlightenment!



Follow ups