From 2bd6eecaa68e2a93b34c289d5937f2ffa4608977 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 12 Jun 2013 16:01:18 +0530 Subject: [PATCH] [email] [communication] fixes - use profile's email address to send email in Communication Composer --- core/doctype/communication/communication.py | 5 +- public/js/wn/views/communication.js | 98 ++++++++++++--------- webnotes/utils/email_lib/__init__.py | 3 - webnotes/utils/email_lib/smtp.py | 4 + 4 files changed, 60 insertions(+), 50 deletions(-) diff --git a/core/doctype/communication/communication.py b/core/doctype/communication/communication.py index 56366a6d6e..c24330bbb7 100644 --- a/core/doctype/communication/communication.py +++ b/core/doctype/communication/communication.py @@ -71,15 +71,12 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s if sent_via: if hasattr(sent_via, "get_sender"): - d.sender = sent_via.get_sender(d) + d.sender = sent_via.get_sender(d) or d.sender if hasattr(sent_via, "get_subject"): d.subject = sent_via.get_subject(d) if hasattr(sent_via, "get_content"): d.content = sent_via.get_content(d) - if not d.sender: - d.sender = webnotes.session.user - from webnotes.utils.email_lib.smtp import get_email mail = get_email(d.recipients, sender=d.sender, subject=d.subject, msg=d.content) diff --git a/public/js/wn/views/communication.js b/public/js/wn/views/communication.js index 5f3a9da253..1142765d51 100644 --- a/public/js/wn/views/communication.js +++ b/public/js/wn/views/communication.js @@ -227,52 +227,64 @@ wn.views.CommunicationComposer = Class.extend({ .find("[data-file-name]:checked"), function(element) { return $(element).attr("data-file-name"); }) - - _p.build(form_values.select_print_format || "", function(print_format_html) { - if(form_values.attach_document_print) { - var print_html = print_format_html - if(cint(wn.boot.send_print_in_body_and_attachment)) { - form_values.content = form_values.content - + "


" + print_html; - } else { - form_values.content = form_values.content + "

" - + "Please see attachment for document details.

" - } + + // if(form_values.attach_document_print) { + _p.build(form_values.select_print_format || "", function(print_format_html) { + me.send_email(btn, form_values, selected_attachments, print_format_html); + }); + // } else { + // me.send_email(btn, form_values, selected_attachments); + // } + }); + }, + + send_email: function(btn, form_values, selected_attachments, print_format_html) { + var me = this; + + if(form_values.attach_document_print) { + var print_html = print_format_html; + if(cint(wn.boot.send_print_in_body_and_attachment)) { + form_values.content = form_values.content + + "


" + print_html; + } else { + form_values.content = form_values.content + "

" + + "Please see attachment for document details.

" + } + } else { + var print_html = ""; + } + + wn.call({ + method:"core.doctype.communication.communication.make", + args: { + sender: wn.user_info(user).fullname + " <" + wn.boot.profile.email + ">", + recipients: form_values.recipients, + subject: form_values.subject, + content: form_values.content, + doctype: me.doc.doctype, + name: me.doc.name, + lead: me.doc.lead, + contact: me.doc.contact, + company: me.doc.company || sys_defaults.company, + send_me_a_copy: form_values.send_me_a_copy, + send_email: form_values.send_email, + print_html: print_html, + attachments: selected_attachments + }, + btn: btn, + callback: function(r) { + if(!r.exc) { + if(form_values.send_email) + msgprint("Email sent to " + form_values.recipients); + me.dialog.hide(); + cur_frm.reload_doc(); } else { - print_html = ""; + msgprint("There were errors while sending email. Please try again.") } - wn.call({ - method:"core.doctype.communication.communication.make", - args: { - sender: wn.user_info(user).fullname + " <" + wn.boot.profile.email + ">", - recipients: form_values.recipients, - subject: form_values.subject, - content: form_values.content, - doctype: me.doc.doctype, - name: me.doc.name, - lead: me.doc.lead, - contact: me.doc.contact, - company: me.doc.company || sys_defaults.company, - send_me_a_copy: form_values.send_me_a_copy, - send_email: form_values.send_email, - print_html: print_html, - attachments: selected_attachments - }, - btn: btn, - callback: function(r) { - if(!r.exc) { - if(form_values.send_email) - msgprint("Email sent to " + form_values.recipients); - me.dialog.hide(); - cur_frm.reload_doc(); - } else { - msgprint("There were errors while sending email. Please try again.") - } - } - }); - }) - }); + } + }); }, + setup_earlier_reply: function() { var fields = this.dialog.fields_dict; var comm_list = cur_frm.communication_view diff --git a/webnotes/utils/email_lib/__init__.py b/webnotes/utils/email_lib/__init__.py index cc9300ffbd..cac740f08f 100644 --- a/webnotes/utils/email_lib/__init__.py +++ b/webnotes/utils/email_lib/__init__.py @@ -30,9 +30,6 @@ def sendmail_md(recipients, sender=None, msg=None, subject=None): def sendmail(recipients, sender='', msg='', subject='[No Subject]'): """send an html email as multipart with attachments and all""" - if webnotes.mute_emails or getattr(conf, "mute_emails", False): - return - from webnotes.utils.email_lib.smtp import get_email get_email(recipients, sender, msg, subject).send() diff --git a/webnotes/utils/email_lib/smtp.py b/webnotes/utils/email_lib/smtp.py index 5724fb15e6..022a2adde0 100644 --- a/webnotes/utils/email_lib/smtp.py +++ b/webnotes/utils/email_lib/smtp.py @@ -231,6 +231,10 @@ class EMail: def send(self, as_bulk=False): """send the message or add it to Outbox Email""" + if webnotes.mute_emails or getattr(conf, "mute_emails", False): + webnotes.msgprint("Emails are muted") + return + import smtplib try: SMTPServer().sess.sendmail(self.sender, self.recipients + (self.cc or []),