Skip to content

Instantly share code, notes, and snippets.

@tejastank
Created July 12, 2012 19:55
Show Gist options
  • Save tejastank/3100527 to your computer and use it in GitHub Desktop.
Save tejastank/3100527 to your computer and use it in GitHub Desktop.
OpenERP-smpt-email-send-code
"""
Within OpenERP sometime its critical to manage simple email sending feature.
So to make easy it, use below code inside your model.
Just add this method inside your model. also set smtp user and password details with method.
This works fine with a lots of system.
== To use ==
Need to import a package name "smtplib"
import smtplib
smtplib enabled smtp email sending feature.
Thanks,
:)
"""
import smtplib
def send_smtp_email(self, cr, uid, email_from, email_to, subject, body):
smtp_email_user = '333@gmail.com'
smtp_email_pwd = '131313'
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(smtp_email_user, smtp_email_pwd)
header = 'To:' + email_to + '\n' + 'From: ' + email_from + '\n' + 'Subject:'+ subject +' \n'
msg = header + '\n ' + body + ' \n\n'
res = smtpserver.sendmail(email_from, email_to, msg)
smtpserver.close()
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment