Merge pull request #20542 from phot0n/contact-us
fix!: contact us email reply
This commit is contained in:
commit
32724a8eb7
3 changed files with 28 additions and 52 deletions
|
|
@ -23,23 +23,22 @@ frappe.ready(function() {
|
|||
}
|
||||
|
||||
$("#contact-alert").toggle(false);
|
||||
frappe.send_message({
|
||||
subject: $('[name="subject"]').val(),
|
||||
sender: email,
|
||||
message: message,
|
||||
frappe.call({
|
||||
type: "POST",
|
||||
method: "frappe.www.contact.send_message",
|
||||
args: {
|
||||
subject: $('[name="subject"]').val(),
|
||||
sender: email,
|
||||
message: message,
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.message==="okay") {
|
||||
if (!r.exc) {
|
||||
frappe.msgprint('{{ _("Thank you for your message") }}');
|
||||
} else {
|
||||
frappe.msgprint('{{ _("There were errors") }}');
|
||||
console.log(r.exc);
|
||||
}
|
||||
$(':input').val('');
|
||||
}
|
||||
}, this);
|
||||
return false;
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var msgprint = function(txt) {
|
||||
|
|
|
|||
|
|
@ -213,15 +213,6 @@ $.extend(frappe, {
|
|||
)
|
||||
.appendTo(document.body);
|
||||
},
|
||||
send_message: function (opts, btn) {
|
||||
return frappe.call({
|
||||
type: "POST",
|
||||
method: "frappe.www.contact.send_message",
|
||||
btn: btn,
|
||||
args: opts,
|
||||
callback: opts.callback,
|
||||
});
|
||||
},
|
||||
has_permission: function (doctype, docname, perm_type, callback) {
|
||||
return frappe.call({
|
||||
type: "GET",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: MIT. See LICENSE
|
||||
|
||||
from contextlib import suppress
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import now
|
||||
from frappe.rate_limiter import rate_limit
|
||||
from frappe.utils import validate_email_address
|
||||
|
||||
sitemap = 1
|
||||
|
||||
|
|
@ -22,38 +25,23 @@ def get_context(context):
|
|||
return out
|
||||
|
||||
|
||||
max_communications_per_hour = 1000
|
||||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def send_message(subject="Website Query", message="", sender=""):
|
||||
if not message:
|
||||
frappe.response["message"] = "Please write something"
|
||||
return
|
||||
@rate_limit(limit=1000, seconds=60 * 60)
|
||||
def send_message(sender, message, subject="Website Query"):
|
||||
sender = validate_email_address(sender, throw=True)
|
||||
|
||||
if not sender:
|
||||
frappe.response["message"] = "Email Address Required"
|
||||
return
|
||||
with suppress(frappe.OutgoingEmailError):
|
||||
if forward_to_email := frappe.db.get_single_value("Contact Us Settings", "forward_to_email"):
|
||||
frappe.sendmail(recipients=forward_to_email, reply_to=sender, content=message, subject=subject)
|
||||
|
||||
# guest method, cap max writes per hour
|
||||
if (
|
||||
frappe.db.sql(
|
||||
"""select count(*) from `tabCommunication`
|
||||
where `sent_or_received`="Received"
|
||||
and TIMEDIFF(%s, modified) < '01:00:00'""",
|
||||
now(),
|
||||
)[0][0]
|
||||
> max_communications_per_hour
|
||||
):
|
||||
frappe.response[
|
||||
"message"
|
||||
] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later"
|
||||
return
|
||||
frappe.sendmail(
|
||||
recipients=sender,
|
||||
content=f"<div style='white-space: pre-wrap'>Thank you for reaching out to us. We will get back to you at the earliest.\n\n\nYour query:\n\n{message}</div>",
|
||||
subject="We've received your query!",
|
||||
)
|
||||
|
||||
# send email
|
||||
forward_to_email = frappe.db.get_single_value("Contact Us Settings", "forward_to_email")
|
||||
if forward_to_email:
|
||||
frappe.sendmail(recipients=forward_to_email, sender=sender, content=message, subject=subject)
|
||||
# for clearing outgoing email error message
|
||||
frappe.clear_last_message()
|
||||
|
||||
# add to to-do ?
|
||||
frappe.get_doc(
|
||||
|
|
@ -66,5 +54,3 @@ def send_message(subject="Website Query", message="", sender=""):
|
|||
status="Open",
|
||||
)
|
||||
).insert(ignore_permissions=True)
|
||||
|
||||
return "okay"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue