I want to send a mass email to all employees with their names how is that possible? Newsletter has no option for doctype fields
Hope this will help.
it works with email template but not newsletter
Hi @Khadija,
we had a similar requirement on newsletters, where they should be personalised (customer name, …). Have have solved this by extending the newsletter function with a custom button “Send with dynamic content” and added some server side code which replaces predefined strings in the newsletter body. You can find the source here:
The custom script looks like this:
frappe.ui.form.on("Newsletter", {
refresh: function(frm) {
if ((!frm.doc.__islocal) && (frm.doc.email_sent == 0)) {
frm.add_custom_button(__("Dynamisch senden"), function() {
send_dynamic(frm);
});
frm.add_custom_button(__("Vorlage einlesen"), function() {
load_template(frm);
});
}
}
});
function send_dynamic(frm) {
frappe.call({
method: 'erpnextswiss.erpnextswiss.dynamic_newsletter.enqueue_send_dynamic_newsletter',
args: {
newsletter: frm.doc.name
},
callback: function(r) {
frappe.msgprint(
__("The newsletter has been added to the sending queue. It will be sent in the next few minutes."),
__("Newsletter sending") );
}
});
}
function load_template(frm) {
frappe.prompt([
{'fieldname': 'template', 'fieldtype': 'Link', 'label': 'Vorlage', 'options': 'Terms and Conditions', 'reqd': 1}
],
function(values){
frappe.call({
"method": "frappe.client.get",
"args": {
"doctype": "Terms and Conditions",
"name": values.template
},
"callback": function(response) {
var terms = response.message;
if (terms) {
cur_frm.set_value('message', terms.terms);
}
}
});
},
'Vorlage auswählen',
'OK'
)
}
Hope this helps. (Maybe this also helps How to add custom fields to Newsletter using jinja?)
Thank you, it fulfilled the purpose
This seems amazing and so handy Lasalesi. Except I can’t get it to work for me
Versions I am using:
ERPNext: v12.9.3 (version-12)
Frappe Framework: v12.6.1 (version-12)
What I did and what happened so far:
- Created and installed a custom app.
- Added the dynamic_newsletter.py file in the custom app.
- Added the client-side script for the Newsletter doctype.
- Ran bench migrate && bench restart for compiling the Python.
- Set up a test template in the Terms & Conditions.
- Created a new newsletter, loaded the template (works )
- Pressing “send with dynamic content” also successfully returned the message saying "“The newsletter has been added to the sending queue. It will be sent in the next few minutes.”
- After a couple of moments, refreshing the newsletter also updates the newsletter status to “sent”.
- Absolutely no related errors in the Error Log but no newsletter emails also
Hope someone can help. TIA
Best,
Shubham
were there mails in email queue?
Have you checked if there are any errors in the background processes (Settings > Background Jobs > show failed)?
No. I noticed that it is not queuing up the mails at all. Maybe I made some mistake while modifying the code suitably for my use case.
Could it also probably be due to version difference? I am on v12 and maybe this was written for an older version?
I just checked and I can’t see any errors in the background processes as of now. Will try and send the dynamic newsletters again. That is when I will again check if any background jobs are failing.
Thanks a lot for the reply, btw.
Version should not be an issue, we are also using v12.
Would this work for v14? Maybe one of us could write a generic implementation that could be merged back to core itself.
Personalised newsletters are a must today.