This question has been flagged
1 Reply
10019 Views

Hi guys,

Every now and then I play around with the mail module and the features but I seem to run stuck on one point, everytime.
Imagine that you have three users: UserA, UserB and UserC.
Its perfectly possible to configure an incoming mail server for every user (so three incoming mail servers) however when you want to create three outgoing mail servers the problems start.
You can create three different outgoing mailservers but the one with the highest priority will always be used, no matter what.

My question is, what is the correct way to create multiple outgoing mail servers and use all of them depending on the user that is sending an email? An example:

UserA wants to send a message to a customer which he has just created under 'Sales' > 'Contacts'. He types a messages and submits this. It will now be e-mailed with the outgoing mailserver with the lowest priority, lets assume this is OutgoingmailserverUserA.
When UserB now wants to send an email out to the same customer but from another e-mail (OutgoingmailserverUserB) it will be sent with the mailserver from OutgoingmailserverUserA, since this has the lowest priority.

How can I create multiple outgoing mailservers and send an e-mail out depending on the user? This feature does not seem to exist out of the box and the only option seems to be to have one outgoing mailserver for all users?..

Thanks,
Yenthe

Avatar
Discard

Use multiple outgoing mail servers for multiple users you can use this module: https://apps.odoo.com/apps/modules/14.0/fl_outgoing_mail_server_user/

Best Answer

Yenthe,

I have asked same question before few days :

https://www.odoo.com/forum/help-1/question/how-to-send-email-by-userwise-modelwise-using-differnent-outgoing-servers-87768

I made a module for this and added a many2one field in outgoing server ( ir.mail_server model ) At the time of send mail, i checked if there is no default mail_server_id available then system will get the related mail server from "uid".

For example, see following method. ( Please give attention to bold lines )

class ir_mail_server(osv.osv):
    _inherit = "ir.mail_server"
    _columns = {
                'user_id_ept':fields.many2one('res.users','User',help='When user is assigned then \
                                    at the time of email sending from Odoo if no outgoing server found then \
                                    system will take the server which is assigned to this user.') 
                }
    
    def send_email(self, cr, uid, message, mail_server_id=None, smtp_server=None, smtp_port=None,
                   smtp_user=None, smtp_password=None, smtp_encryption=None, smtp_debug=False,
                   context=None):
        mail_server = mail_server_id
        if not mail_server :
            user_obj = self.pool.get('res.users').browse(cr,uid,uid)
            email = user_obj.partner_id and user_obj.partner_id.email or False
            if email :
                mail_server_ids = self.search(cr, SUPERUSER_ID, [('user_id_ept','=',uid)], order='sequence', limit=1)
                if mail_server_ids :
                    mail_server = mail_server_ids[0]
        return super(ir_mail_server,self).send_email(cr, uid, message,
                                                    mail_server_id=mail_server,
                                                    context=context)  


In a nutshell, before Odoo checks low priority outgoing server in case of if there is no mail server specified, I added condition to check outgoing server related to user configured on it with "uid". ( this sentence may be hard to understand ;) )

From my thinking this is the only way. However in my question i raised another interesting point. If you have a time please read it as well.

Latest Update : This module is out to Odoo store now. It is a Free App. You can download from this link

Avatar
Discard
Author

Hi Emipro, thanks a lot for your reply! I was thinking about doing exactly the same and I see that as the only option too. Is your module available anywhere on Github or something? It would be a waste if I would have to program the entire thing again while you've made this. Perhaps this is something you could put online on apps? I honestly think this would be great. I'll upvote this for now but I'll leave the accepting open for other responses too. :)

Yenthe, that module is already available at myside but with more specific features. Tonight I will make it separate and post in Odoo Apps for free to download. Also I will inform you to your email so you can download it. Give me your email. (y)

Author

Great Emipro! You can always drop me an e-mail at yenthe.vanginneken@vanroey.be , also to talk about other things regarding Odoo. Looking forward to your module, thanks!

Yenthe, I sent you module on your specified email address. Enjoy !

Could you please update the app link?