Configuring Email server in open ERP version 6.01

 Introduction

It would be very useful if we know how can we send mails through open ERP under program control as it offers flexibility of content. This passage detains about how can we configure smtp servers in Open ERP Version 6.01 (stable) and how can we add methods that sends mail to your desired mail id with desired content.

Module smtpclient

You may be wondering it could be really difficult to configure smpt server and send mail through open ERP. But its just a matter of installing the custom module smtpclient available for free download from the net. A few menus will be appearing after installing the smtp client module as given below.

Administration/Configuration/Email Servers

  • Administration/Configuration/Email Servers/SMTP Server

  • Administration/Configuration/Email Servers/Email Server History

  • Administration/Configuration/Email Servers/Message Queue

On clicking on smtpservers it opens up the list of smtp servers configured. You can add new smtp server. It stores server configuration details. Where in you can give a name to the server, specify its type and all. Infact depending on your usage say if you want mail delivery for multiple purposes you can configure mail servers as a different type of server and if you want with different email ids as you desire.

Configuring a mail server

  1. Create a new server by pressing on the new button in the menu bar

  2. Now a form will be open where in you can enter details of the server

  3. Fill in all the fields and send the verification code to a mail id

  4. Open the mail box to find the verification code

  5. When you have the verification code verify the server using the wizard ‘Verify server’ wizard on the right toolbar in the form and start the server.

    1. If you have entered an invalid verification code then the server will not be verified and you cannot start the server and proceed with email sending.

    2. If you did not recieve the verification code probably there is an error with the email id and password configured for the server. Find errors in the server log for details.

  6. When the server status is ‘verified‘ and server statue is ‘running‘ then you can proceed with mail sending

Sending mails through Open ERP

Now you have a verified smtp server with you and can proceed with mail sending. We can use functions in the object ’email.smtpclient’ to send mail where in you can find the functions as you have the source with you.

Actually we do queue up the mails to be send in a table and run a scheduler at regular intervals to clear up the queues. We have several queing options in the smtp server. We can keep the queue though the mail is send or delete the mails as soon as its sent.

You can use send_email function to send mails in the ’email.smtpclient’ object. The mandatory arguements are as given below. It supports sending the attatchments as files or as reports ( reports are generated before the mail is sent)

cr >> database cursor
uid >> user id
server_id >> smtp_server_id # id of the email.smtpclient record
emailto >> email_id to which the mail is to be delivered
subject >> subject of the mail to be delivered
body >>
body of the mail to be delivered #not mandatory

Sample Code



dest=’test_email@gmail.com’#to email address
smtpserver_id = smtp_obj.select(cr, uid, ‘approval’)#getting the id of smtp server configured as type “approval
if smtpserver_id is False:
raise osv.except_osv(_(‘Configuration Fault’), _(‘Configure the smptpserver properly’))
body = body.replace(‘\n’,‘<br/>’)#replacing new lines with branch tag
body = body.encode(‘utf-8’)#encoding the body text to utf-8 format
state = self.pool.get(email.smtpclient).send_email(cr,uid,smtpserver_id, dest, subject.encode(‘utf-8’), body, attachments=[],context={})
cr.commit()

</code>



Web links:



Comments

Anonymous: NameError: global name 'smtp_obj' is not define ".

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Anonymous says:

    Hi.
    Am trying to send a verfication code with smtpclient and i get a server time out error when i consullt the log files. I am using ubuntu 10.04 with version 6.03. Totally baffled as the settings are correct and work with the marketting module on the same installation.
    Thanks

  2. Anonymous says:

    NameError: global name ‘smtp_obj’ is not define

© 2020 Zesty Beanz Pvt Ltd All Rights Reserved.