Custom email notification content

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
eleyes
Posts: 4
Joined: 14 Apr 2020, 23:33

Custom email notification content

Post by eleyes »

Dear mantis forum members.
My question is regarding the email content sent when notifying users related to tickets. I know there are already some posts talking about it and that there isn't yet a visual way to modify it.
However that, and knowing the PHP file i must modify in order to customize email contents, i'd please ask if someone would point me in the right direction inside this PHP file.
My objective is to shorten the content of the mail that informer receives.

Thanks a lot in advance for your help.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Custom email notification content

Post by cas »

Look in core/email_api.php :mrgreen:
eleyes
Posts: 4
Joined: 14 Apr 2020, 23:33

Re: Custom email notification content

Post by eleyes »

Thanks a lot for your reply!
I am investigating the content of this file and isn't quite understandable for my level... Sorry.
If someone could point me to the line number or any other reference inside this file, where to modify, i will appreciate a lot.
Best,
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Custom email notification content

Post by cas »

If you check bug_update.php, you will find at the bottom og the script the following:

Code: Select all

# Allow a custom function to respond to the modifications made to the bug. Note
# that custom functions are being deprecated in MantisBT. You should migrate to
# the new plugin system instead.
helper_call_custom_function( 'issue_update_notify', array( $f_bug_id ) );

# Send a notification of changes via email.
if( $t_resolve_issue ) {
	email_resolved( $f_bug_id );
	email_relationship_child_resolved( $f_bug_id );
} else if( $t_close_issue ) {
	email_close( $f_bug_id );
	email_relationship_child_closed( $f_bug_id );
} else if( $t_reopen_issue ) {
	email_bug_reopened( $f_bug_id );
} else if( $t_existing_bug->handler_id != $t_updated_bug->handler_id ) {
	email_owner_changed( $f_bug_id, $t_existing_bug->handler_id, $t_updated_bug->handler_id );
} else if( $t_existing_bug->status != $t_updated_bug->status ) {
	$t_new_status_label = MantisEnum::getLabel( config_get( 'status_enum_string' ), $t_updated_bug->status );
	$t_new_status_label = str_replace( ' ', '_', $t_new_status_label );
	email_bug_status_changed( $f_bug_id, $t_new_status_label );
} else {
	email_bug_updated( $f_bug_id );
} 
So depending on the change another routine is used, all within email_api.php.
Try to follow the code to find where you would like to change something.
eleyes
Posts: 4
Joined: 14 Apr 2020, 23:33

Re: Custom email notification content

Post by eleyes »

Thanks a lot for your reply! Following the info you provided me, it lead me to the "email_build_visible_bug_data" function where it seems that if i comment some parts of it, the notification info will be modified.
I'll try and post back here.
Thanks again.
Starbuck
Posts: 219
Joined: 14 Feb 2006, 02:53
Location: USA
Contact:

Re: Custom email notification content

Post by Starbuck »

Ugh, I've had email_api.php sitting on my desktop for months and I need to make changes.
It's just staring at me. "Go ahead, I dare you to start messing with me."
I haven't allocated the time to wrestle with the beast.

I love that Mantis is so versatile in some ways, but it's so hard-coded in others...
I know: "If you don't like it, change it and submit a PR".
Note that thing about time.

In the end, there can be only one... :twisted:
If you want Mantis to work differently, use or create a plugin. Visit the Plugins forums.
Ask developers to create a plugin that you need - and motivate them to help you!
eleyes
Posts: 4
Joined: 14 Apr 2020, 23:33

Re: Custom email notification content

Post by eleyes »

Here is my little contribution regarding this topic.
The lines in /core/email_api.php from 1706 to 1993 are related to what finally contains the email notification:

Some examples (just comment it if don't want to include it in email):

Reporter:

Code: Select all

$t_message .= email_format_attribute( $p_visible_bug_data, 'email_reporter' );
Ticket priority:

Code: Select all

if ( isset( $p_visible_bug_data[ 'email_priority' ] ) ) {
		$p_visible_bug_data['email_priority'] = get_enum_element( 'priority', $p_visible_bug_data['email_priority'] );
		$t_message .= email_format_attribute( $p_visible_bug_data, 'email_priority' );
	}
Custom fields:

Code: Select all

foreach( $p_visible_bug_data['custom_fields'] as $t_custom_field_name => $t_custom_field_data ) {
		$t_message .= utf8_str_pad( lang_get_defaulted( $t_custom_field_name, null ) . ': ', $t_email_padding_length, ' ', STR_PAD_RIGHT );
		$t_message .= string_custom_field_value_for_email( $t_custom_field_data['value'], $t_custom_field_data['type'] );
		$t_message .= " \n";
	}
And so on.

I hope it helps someone.

Best,
Post Reply