Show username while sending email

Hello dears

Is there any way to show user name with email while sending email in any document like assign ??

coz we have emails like from

sales1@name.com
.
.
.
sales30@name.com

this will be impossible to use without username

how can we show username with e-mail address

Since the Assigned User ID is a Linked Doctype it becomes way too easier. If you Customize ToDo, you will find this below in the table:

This is for the user who assigned the ToDo.

You can do the same for the user who has been assigned the ToDo. The field is this:

Just repeat for field owner what is shown above for the field assigned_by and your problem is solved.

Also, avoid Edit Doctype and use Customize Form and export fixtures to your app

Thanks for reply

But actually i wanna to customize email not todo

like that

which has no user name to identify the e-mail addresses

Oh okay. This can be done if you can write a custom python query. Do you have access to Python ?

yes i have

any idea bout how to ??

Check this:

https://github.com/frappe/frappe/blob/22f4433406b8583d05ea4eaeb9dfe2cc10d20a2c/frappe/email/init.py#L24

JS call:

@magic-overflow thanks for your reply

i`v replaced your both files with mine but nothing changed ??

If change js file, you need to run bench build

Edit:
And this command too as u change both
bench restart
bench --site sitename clear-cache

done but return nothing

Ur change effected but it’s not right. Can u show me ur changes?

moved original files to another name and downloaded your files in the same location

just replaced the both files

Ok.
You can use ur original file, and delete file u downloaded.

The link I showed you it’s just file that u have to edit the code first before replace ur file.

What’s ur erpnext version?

erpnext 10.1.72
frappe 10.1.61

Please make sure you backup your file, before change as below:

If you can wait, this feature is out of the box V11.

frappe-bench/apps/frappe/frappe/email/__init__.py

Replace method get_contact_list with below

@frappe.whitelist()
def get_contact_list(txt):
	"""Returns contacts (from autosuggest)"""
	txt = txt.replace('%', '')

	def get_users():
		return filter(None, frappe.db.sql('select email as value, concat(first_name, " ", last_name) as description from tabUser where email like %s',
			('%' + txt + '%'), as_dict = True))
	try:
		out = filter(None, frappe.db.sql("""select distinct email_id as value, concat(first_name, " ", last_name) as description from `tabContact` 
			where email_id like %(txt)s or concat(first_name, " ", last_name) like %(txt)s order by
			if (locate( %(_txt)s, concat(first_name, " ", last_name)), locate( %(_txt)s, concat(first_name, " ", last_name)), 99999),
			if (locate( %(_txt)s, email_id), locate( %(_txt)s, email_id), 99999)""",
		        {'txt': "%%%s%%" % frappe.db.escape(txt),
	            '_txt': txt.replace("%", "")
		        }, as_dict = True)
		)
		if not out:
			out = get_users()
	except Exception as e:
		if e.args[0]==1146:
			# no Contact, use User
			out = get_users()
		else:
			raise

	return out

frappe-bench/apps/frappe/frappe/public/js/frappe/views/communication.js

replace function setup_awesomplete_for_input with below:

setup_awesomplete_for_input: function(input) {
		function split(val) {
			return val.split( /,\s*/ );
		}
		function extractLast(term) {
			return split(term).pop();
		}

		var awesomplete = new Awesomplete(input, {			
			minChars: 0,
			maxItems: 99,
			autoFirst: true,
			data: function(item) {
				if(!(item instanceof Object)) {
					var d = {"value": item};
					item = d;
				}

				return {
					label: item.label || item.value,
					value: item.value
				};
			},
			item: function(item) {
				var d = this.get_item(item.value);
				if(!d) {
					d = item;
				}

				if (!d.label) {
					d.label = d.value;
				}

				var _label = d.label;
				var html = "<strong>" + _label + "</strong>";
				if(d.description && d.value!==d.description) {
					html += '<br><span class="small">' + __(d.description) + '</span>';
				}

				return $('<li></li>')
					.data('item.autocomplete', d)
					.prop('aria-selected', 'false')
					.html('<a><p>' + html + '</p></a>')
					.get(0);
			},
			sort: () => {
				return 0;
			},
			list: [],
			filter: function(text, input) { return true },
			replace: function(text) {
				var before = this.input.value.match(/^.+,\s*|/)[0];
				this.input.value = before + text + ", ";
			}
		});
		var delay_timer;
		var $input = $(input);
		$input.on("input", function(e) {
			clearTimeout(delay_timer);
			delay_timer = setTimeout(function() {
				var term = e.target.value;
				frappe.call({
					method:'frappe.email.get_contact_list',
					args: {
						'txt': extractLast(term) || '%'
					},
					quiet: true,
					callback: function(r) {
						awesomplete.list = r.message || [];
					}
				});
			},250);
		});
	}

Then run command:

bench clear-cache
bench build
bench restart

4 Likes

thanks for your efforts

it works !!

Glad it helped.

2 Likes